Program based on 'Multilevel Inheritance' :-


#include<iostream.h>
#include<conio.h>

class A
{
public:
int x;
void readx()
{
cout<<"Enter value of x:";
cin>>x;
}
};

class B:public A
{
public:
int y;
void ready()
{
cout<<"Enter value of y:";
cin>>y;
}
};

class C:public B
{
private:
int z;
public:
void readz()
{
cout<<"Enter value of z:";
cin>>z;
}

void product()
{
cout<<endl<<"Product:"<<x*y*z;
}
};

void main()
{
clrscr();
C obj;
obj.readx();
obj.ready();
obj.readz();
obj.product();
getch();
}

Output:


Enter value of x:5
Enter value of y:5
Enter value of z:5

Product:125

			

Previous Next