C++ program for Hierarchical inheritance

#include<iostream.h>
#include<conio.h>
class m{
protected:
int m;
public:
m(){
m=10;
}
};
class n:public m{
protected:
int n;
public:
n(){
n=20;
}
void showmn();
};
void n::showmn(){
cout<<"M = "<<m<<endl<<"N = "<<n<<endl;
}
class o:public m{
protected:
int o;
public:
o(){
o=30;
}
void showmo();
};
void o::showmo(){
cout<<"M = "<<m<<endl<<"O = "<<o<<endl;
}
void main(){
clrscr();
n obj1;
o obj2;
obj1.showmn();
obj2.showmo();
getch();
}

No comments:

Post a Comment