What is the output of the following C++ program?

#include <iostream>
using namespace std;
class Shape {
public:
    virtual int area() = 0;
};
class Square : public Shape {
public:
    int area() override {
        return 4 * 4;
    }
};
int main() {
    Square s;
    cout << s.area();
    return 0;
}
                        

Options

  • B. 8
  • C. 16
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

C. 16

Detailed Explanation

Correct Answer: Option C

Explanation:
Shape is abstract because area() is a pure virtual function. Square implements area() and becomes a concrete class. Since the function returns 4 * 4, the output is 16.