-
What is the output of this program?
#include <iostream>
using namespace std;
class PolygonShape
{
protected:
int W, H;
public:
void set_values (int num1, int num2)
{
W = num1; H = num2;}
};
class outputA
{
public:
void output (int k);
};
void outputA::output (int k)
{
cout << k << endl;
}
class RectangleShape: public PolygonShape, public outputA
{
public:
int Area ()
{
return (W * H);
}
};
class triangleShape: public PolygonShape, public outputA
{
public:
int Area()
{
return (W * H / 2);
}
};
int main ()
{
RectangleShape RectObject;
triangleShape TrgObject;
RectObject.set_values (3, 4);
TrgObject.set_values (3, 4);
RectObject.output (RectObject.Area());
TrgObject.output (TrgObject.Area());
return 0;
}
-
- 12
6 - 3
4 - Compilation Error
- Runtime Error
- None of these
- 12
Correct Option: A
We are using the multiple inheritance to find the area of rectangle and triangle.