Question OOP-POLY-0041
MediumWhat is the output of this code?
#include <iostream>
using namespace std;
class Shape {
public:
virtual double area() { return 0; }
};
class Sq : public Shape {
double s;
public:
Sq(double x) : s(x) {}
double area() override { return s * s; }
};
int main() {
Shape *a[2] = { new Shape(), new Sq(3) };
cout << a[0]->area() + a[]->();
}
- A.
18
- B.
3
- C.
Sign up free to see the answer and a step-by-step explanation.