Program of Hierarchical Inheritance

/*Program of Hierarchical Inheritance*/

#include
#include
class A
{
int q;
public:
void getdata(int w)
{
q=w;
}
void display()
{
cout<<“\n\nq=”<<q<<“\nI am the member of Class A\n”;
}
};
class B:public A
{
int e;
public:
void setdata(int r)
{
e=r;
}
void show()
{
cout<<“\n\ne=”<<e<<“\nI am the member of Class B derived from Class A\n”;
}
};
class C:private A
{
int t;
public:
void putdata()
{
t=5;
cout<<“\n\nt=”<<t<<“\nI am the member of Class C derived from Class A\n”;
}
void output()
{
getdata(t);
display();
}
};
int main()
{
C c;
c.putdata();
c.output();
B b;
b.getdata(2);
b.display();
b.setdata(4);
b.show();
getch();
return 0;
}

OUTPUT :

t=5
I am the member of Class C derived from Class A

q=5
I am the member of Class A

q=2
I am the member of Class A

e=4
I am th member of Class B derived from Class A







Leave a Reply

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