Question 61
HardWhat is the output of this code?
#include <iostream>
using namespace std;
class Shape {
public:
virtual double area() const = 0;
virtual ~Shape() = default;
double twice() const { return 2 * area(); }
};
class Sq : public Shape {
double s;
public:
Sq(double x) : s(x) {}
double area() const override { return s * s; }
};
int main() {
const Shape &s = Sq(3);
cout << s.twice();
}
- A.
9
- B.
Compilation error
- C.
0
- D.
18
Sign up free to see the answer and a step-by-step explanation.