Description:
Here some examples of "Inheritance" (important concept of c++) are presented.
CODE:
Here some examples of "Inheritance" (important concept of c++) are presented.
CODE:
#include<iostream>
#include<conio.h>
using namespace std;
class B
{
public:
int m,a;
int product1()
{
return a*m;
}
};
class D:public B
{
public:
int n;
int product2()
{
return
n*product1();
}
};
int main()
{
D d1;
d1.m=5;
d1.a=4;
d1.n=3;
cout<<"product1
= "<<d1.product1()<<endl;
cout<<"product2
= "<<d1.product2()<<endl;
getche();
return 0;
}
OUTPUT:
product1 = 20
product2 = 60
No comments:
Post a Comment