Source code
#include <iostream>
using namespace std;
class grandfather{
private:
string name;
public:
grandfather(string n){
name=n;
}
};
class father: public grandfather{
private:
string name;
public:
father(string n,string n2): grandfather(n){
name=n2;
}
};
class child: public father{
private:
string c_name;
string f_name;
string g_name;
public:
child(string n,string n2, string n3):father(n,n2){
g_name=n;
f_name=n2;
c_name=n3;
}
void display(){
cout<<"\nName of grandfather: "<<g_name;
cout<<"\nName of father: "<<f_name;
cout<<"\nName of child: "<<c_name;
}
};
int main()
{
child c("John","Mark","Smith");
c.display();
return 0;
}
Output
Comments