You are on page 1of 2

//HYBRID INHERITANCE

#include<iostream>
using namespace std;
class A
//Base class
{
protected:
int l;
public:
A()
{
cout<<"A's constructor\n";}
~A()
{
cout<<"A's destructor\n";}
void len()
{
cout<<"\n\nLength :::\t";
cin>>l;
//Length is entered by user
}
};
class B :public A //Inherits property of class A
{//SINGLE INHERITANCE
protected:
int b,c;
public:
B()
{
cout<<"B's constructor\n";}
~B()
{
cout<<"B's destructor\n";}
void l_into_b()
{
len();
cout<<"\n\nBreadth :::\t";
cin>>b;
//Breadth is entered by user
c=b*l;
//c stores value of length * Breadth i.e. (l*b) .
}
};
class C
{
protected:
int h;
public:
C()
{
cout<<"C's constructor\n";}
~C()
{
cout<<"C's destructor\n";}
void height()
{
cout<<"\n\nHeight :::\t";
cin>>h;
//Height is entered by user
}
};

//Hybrid Inheritance
class D:public B,public C
{//MULTIPLE INHERITANCE
protected:
int res;
public:
D()
{
cout<<"D's constructor\n";}
~D()
{
cout<<"D's destructor\n";}
void result()
{
l_into_b();
height();
res=h*c; //res stores value of c*h where c=l*b and h is height which is entered
by user
cout<<"\n\nResult (l*b*h) :::\t"<<res<<endl<<endl;
}
};
int main()
{
D d1;
d1.result();
}

You might also like