Friday, 24 February 2012

Program Of MULTILEVEL INHERITANCE


#include<iostream.h>
#include<conio.h>
class base
{
private:
int a;
public:
void getdatab(int x)
{
a=x;
}
void displayb()
{
cout<<"\n base value is="<<a;
}
} ;

class derive : public base     // Single Inheritence
{
private:
int b;
public:
void getdatad(int y)
{
b=y;
}
{
cout<<"\n derive value is="<<b;
}
} ;

class derive1 : public derive     // Multilevel Inheritence
{
private:
int c;
public:
void getdatad1(int z)
{
c=z;
}
{
cout<<"\n derive1 value is="<<c;
}
} ;

main()
{
clrscr();
derive1 d1;
d1.getdatab(5);
d1.getdatad(7);
d1.getdatad1(9);
d1.displayb();
d1.displayd();
d1.displayd1();
getch();
}

--------------------------------------------------------------------------------------------------------------------------

where one class can inherit only 
one base class and the derived class 
can become base class
of some other class.


Class 1
|
|
|
Class 2
|
|
|
Class 3

No comments:

Post a Comment