Que-make a program by simple inheritance method?
#include<iostream>
using namespace std;
class krishna
{
public:
int num1, num2,sum ;
};
class second:public krishna
{
public:
void getdata ()
{
cout<<"enter a number :";
cin>>num1;
cout<<"enter a number :";
cin>>num2;
}
};
class third: public second
{
public:
void display ()
{
sum=num1+num2;
cout<<"enter numbers sum is :- "<<sum;
}
};
class fourth: public third
{
};
int main()
{
fourth ob ;
ob.getdata();
ob.display();
return 0;
}
Result:-