Multilevel Inheritance
Program For Multilevel Inheritance:
#include<stdio.h>
class A
{
int a1,a2;
public :
void getdata()
{
cout<<"\n Enter value of a1 and a2";
cin>>a1>>a2;
}
void putdata()
{
cout<<"\n value of a1 is" <<a1"and a2 is"<<a2;
}
};
class B: public A //class B is publicly derived by class A
{
int b1,b2;
public :
void indata()
{
cout<<"\n Enter the value of b1 nad b2";
cin>>b1>>b2;
}
void outdata()
{
cout<<"\n the value of b1 is" <<b1 "and b2 is:<<b2;
}
};
class C: public B
{
int c1,c2;
public
void input()
{
cout<<"\n enter the value of c1 and c2";
cin>>c1>>c2;
}
void output()
{
cout<<"\nvalue of c1 is"<<c1"and c2 is"<<c2;
}
};void main()
{
C obj
obj.getdata(); //member function of class A
obj.indata(); //member function of class B
obj.input(); //member function of class C
obj.putdata(); //member function of class A
obj.outdata(); //member function of class B
obj.output(); //member function of class C
}
Output:
Enter value of a1 and a2
3
4
Enter value of b2 and b2
6
7
Enter value of c1 and c2
8
9
the value of a1 is 3 and a2 is 4
the value of b1 is 6 and b2 is 7
the value of c1 is 8 and c2 is 9