Saturday, 28 April 2012

Program Of Multilevel Inheritance In C++

#include<iostream.h>
#include<conio.h>
class base
{
private:
int a;
public:
{
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;
}
void displayd()
{
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();
}
------------------------------------------
Multilevel Inheritance

Derived a new class from another derived class.It is known 
as multilevel inheritance.
example:
grandfather->father->son.


No comments:

Post a Comment