/* */ Click to Join Live Class with Shankar sir Call 9798158723

What is Hybrid Inheritance ?


Hybrid Inheritance is a method of deriving a class using combination of multilevel or multiple or hierarchical inheritance is called Hybrid Inheritance.


syntax :

class Base
{
// body of Base class
};

class Derived1: access_mode Base
{
//body of Derived1 class which inherit property from base class
};

class Derived2: access_mode Base
{
//body of Derived2 class which inherit property from Base class
};

class Derived3: access_mode Derived1, access_mode Derived2
{
//body of Derived3 class which inherit property from both Derived1 and Derived2 class.
};


Q1.) Example of Multiplelevel Inheritance .
    #include< iostream>
using namespace std;
int a,b,c,d,e;
class A    
{
protected:
public:
	void getab()    
	{
	cout<<"\nEnter a and b value:";
	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; 
	}
};
 
int main()    
{
	D d1;
	d1.result();
	
	return 0;
}
Output
Total Objects: 1
Enter a and b value: 5 10
Enter c value: 15
Enter d value: 20
Addition is :50