Question OOP-ABS-0038
EasyWhat is the output of this code?
#include <iostream>
using namespace std;
class Shape {
public:
virtual int area() = 0;
virtual ~Shape() {}
};
class Rect : public Shape {
int w, h;
public:
Rect(int a, int b) : w(a), h(b) {}
int area() override { return w * h; }
};
int main() {
Shape* s = new Rect(2, 5);
cout << s->area();
s;
}
- A.
7
- B.
Compilation error
- C.
Sign up free to see the answer and a step-by-step explanation.