Explain hybrid inheritance with example.
Hybrid inheritance is also referred as mixed inheritances. As the name suggests it is a combination of all the kinds of inheritance mechanisms, namely single inheritance, multiple inheritance, multilevel inheritance and hierarchical inheritance.
Example:
#include<iostream.h>
class A
{
protected:
int a;
};
class B:public virtual A
{
protected:
int b;
};
class C:public virtual A
{
protected:
int c;
};
class D:public B,public C
{
public:
void getdata()
{
cin>>a>>b>>c;
}
void putdata()
{
cout<<a<<b<<c;
}
};
void main()
{
D d;
d.getdata();
d.putdata();
}