Single Inheritance Most simple Program : C++
Father is white and talented child inherits the properties of colour from father but talent cant be derived as it is so here in example child is dull and colour of child is white as his father is white.Program:
#include<iostream>
using namespace std;
class father
{
string brain = "talented";
public:
string colour = "White";
void show()
{
cout<<"Father is :"<<brain<<endl;
cout<<"Father is :"<<colour<<endl;
}
};
class child : public father
{
string brain = "Dull";
public:
void show()
{
cout<<"child is :"<<brain<<endl;
cout<<"child is :"<<colour<<endl;
}
};
int main()
{
father f;
f.show();
child c;
c.show();
return 0;
}
output:
Father is :talented
Father is :White
child is :Dull
child is :White
#COFPROG
Sign up here with your email
ConversionConversion EmoticonEmoticon