This is single inheritance connected in parallel keeping the base class common. Here classes B and C have no connection; they only inherit from the common base class A.if an object of class B only is created in the main() function, then there will be no trace of the features of class C and vice versa.


Illustrates Hierarchical inheritance and public derivation

#include<iostream>
using namespace std;
class stud
{
private:
char name[20];
char roll[8];
protected:
int age;
public:
void getstudent()
{
cout<<"Name:";
cin>>name;
cout<<"Roll:";
cin>>roll;
cout<<"Age";
cin>>age;
}
void showstudent()
{
cout<<endl<<"Name:"<<name<<endl<<"Roll:"<<roll<<endl;
cout<<"Age:"<<age<<endl;
}
};
class student:public stud
{
private:
int rank;
public:
void inputdata()
{
cout<<"Rank:";
cin>>rank;
}
void outputdata()
{
cout<<"Rank:"<<rank;
}
};
class medical:public students
{
private:
char bloodgp[4];
public:
void cinputdata()
{
inputdata();
cout<<"Blood Group:";
cin>>bloodgp;
}
void coutputdata()
{
outputdata();
cout<<endl<<"Blood Group:"<<bloodgp<<endl;
}
};
void main()
{
academic a;
cot<<"Enter the values of the object of academic:"<<"\n";
a.getstudent();
a.cinputdata();
cout<<"Contents of the object of academic:"<<"\n";
a.showstudent();
a.coutputdata();

//Objects are accessed using same method name 
medical b;
cout<<"Enter the values of the object of edical:"<<"\n";
        b.getstudent();
b.cinputdata();
cout<<"Contents of the object of medical:"<<"\n";
b.showstudent();
b.coutputdata();
}

Output:

Enter the values of the object of academic:
Name :Sai
Roll:101
Age:28
Rank:4
Content of  the object of academic:
Name :Sai
Roll:101
Age:28
Rank:4

Enter the values of the object of academic:
Name :Sai ram
Roll:202
Age:18
Blood Group: O+
Content of  the object of academic:
Name :Sai ram
Roll:202
Age:18
Blood Group: O+

Posted by Unknown On 02:23 1 comment

1 comment:

  1. This is single inheritance connected in parallel keeping the base class common.perfect explanation about inheritance in java programming .its very useful.thanks for your valuable information.java training in chennai | list of java training institutes in chennai

    ReplyDelete

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

Blog Archive

Contact Us


Name

E-mail *

Message *