Home / MCQ Bank / Computer
Computer Inheritance In C Plus Plus

What will be the output of the following C++ code? #include <iostream> using namespace std; class polygon { protected: int width, height; public: void set_values (int a, int b) { width = a; height = b;} }; class output1 { public: void output (int i); }; void output1::output (int i) { cout << i << endl; } class rectangle: public polygon, public output1 { public: int area () { return (width * height); } }; class triangle: public polygon, public output1 { public: int area () { return (width * height / 2); } }; int main () { rectangle rect; triangle trgl; rect.set_values (4, 5); trgl.set_values (4, 5); rect.output (rect.area()); trgl.output (trgl.area()); return 0; }

Select the best option to verify your answer:
Show Correct Answer
Correct Answer: Option C • 20 10

Related Computer Questions

What is the purpose of using a median of three quick sort over standard quick sort? What is the purpose of exception handling in Python? How many parameters does a conversion operator may take? Which of the following function actually fits the linear model? To enable OSPFv3, which of the following would you use?