This is a single inheritance connected in parallel, having two or more base classes and a common derived class. It has the tree structure. Here a class can inherit the properties of two or more classes. The general format for declaring and defining a derived class from multiple base classes is:

class derived : visibility base1, visibility base2,visibility base3,.....{  } ;

where, derived is the derived class name and base1,base2,base3,... are base class names. Visibility is the access specifier used for the derivation.Generally it is public or private. No an object of C ,derived from the base classes A and B will have the feature of both A and B.


Illustrate the multiple inheritance with public derivation

#include<iostream>
using namespace std;
class stud
{
private:
char name[20];
char roll[8];
protected:
int age;
public:
void input()
{
cout<<"Name:";
cin>>name;
cout<<"Roll:";
cin>>roll;
cout<<"Age";
cin>>age;
}
void output()
{
cout<<endl<<"Name:"<<name<<endl<<"Roll:"<<roll<<endl;
cout<<"Age:"<<age<<endl;
}
};
class academic
{
private:
int rank;
public:
void input()
{
cout<<"Rank:";
cin>>rank;
}
void output()
{
cout<<"Rank:"<<rank;
}
};
class medical:public student,public academic
{
private:
char bloodgp[4];
public:
void cinput()
{
student::input(); // input()invoked along with class name
academic::input();
cout<<"Blood Group:";
cin>>bloodgp;
}
void coutput()
{
student::output(); // output()invoked along with class name
academic::output();
cout<<endl<<"Blood Group:"<<bloodgp<<endl;
}
};
void main()
{
medical m;
cout<<"Enter student Details:"<<"\n";
m.cinput();
cout<<"\n Details of a student:"<<"\n";
m.coutput();
}

OUTPUT:

Enter Student Details:
Name:Rahul
Roll:303
Age:18
Rank:2
Blood Group:O+

Details of a Student:
Name:Rahul
Roll:303
Age:18
Rank:2
Blood Group:O+

Other Recommended posts



Posted by Unknown On 03:04 No comments

0 comments:

Post a Comment

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

Blog Archive

Contact Us


Name

E-mail *

Message *