0% found this document useful (0 votes)
43 views1 page

Hierarchical Inheritance

This C++ program defines three classes: A, B, and C, where B and C inherit from A. Class A contains a method to set two integer values, while class B calculates their sum and class C calculates their product. The main function creates instances of B and C, sets their data, and displays the results of the calculations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views1 page

Hierarchical Inheritance

This C++ program defines three classes: A, B, and C, where B and C inherit from A. Class A contains a method to set two integer values, while class B calculates their sum and class C calculates their product. The main function creates instances of B and C, sets their data, and displays the results of the calculations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include<iostream.

h>
#include<conio.h>

class A
{
protected:
int x;
int y;
public:
void getData(int a,int b)
{
x=a;
y=b;
}
};
class B: public A
{
public:
void sum()
{
cout<<"\n Sum is : "<<x+y;
}
};
class C: public A
{
public:
void product()
{
cout<<"\n Product is : "<<x*y;
}
};

int main()
{
clrscr();
B ob1;
C ob2;
ob1.getData(5,7);
ob1.sum();
ob2.getData(4,9);
ob2.product();
getch();
return 0;
}

You might also like