-
What is the output of this program?
#include <iostream>
using namespace std;
class FirstClass
{
protected:
int width, height;
public:
void set_values (int x, int y)
{
width = x; height = y;
}
virtual int area (void) = 0;
};
class SecondClass: public FirstClass
{
public:
int area (void)
{
return (width * height);
}
};
class ThirdClass: public FirstClass
{
public:
int area (void)
{
return (width * height / 2);
}
};
int main ()
{
SecondClass Rectangle;
ThirdClass trgl;
FirstClass * ppoly1 = &Rectangle;
FirstClass * ppoly2 = &trgl;
ppoly1->set_values (3, 6);
ppoly2->set_values (3, 6);
cout << ppoly1 -> area() <<" ";
cout << ppoly2 -> area();
return 0;
}
-
- 3 6
- 6 3
- 9 18
- 18 9
- None of these
Correct Option: D
In this program, We are calculating the area of rectangle and
triangle by using abstract class.