Hybrid inheritance

Hybrid inheritance:

In this type one or more types of inheritance are combined together and used.

hybrid

Example
#include<iostream.h>

#include<conio.h>

int a,b,c,d,e;

class A

{

protected: public: void getab()

{

cout<<“\n Enter the both value of a & b :”;

cin>>a>>b;

}

};

class B:public A

{

protected: public: void getc()

{

cout<<“Enter c value:”;

cin>>c;

}

};

class C

{

protected: public: void getd()

{

cout<<“Enter d value:”;

cin>>d;

}

};

class D:public B,public C

{

protected: public: void result()

{

getab();

getc();

getd();

e=a+b+c+d;

cout<<“\n Addition is :”<<e;

}

};

void main()

{

clrscr();

D d1;

d1.result();

getch();

}

Output

Enter both a and b value: 4

5

Enter c value:6

Enterd value:7

Addition is :22

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *