What is the output of the following C++ program?
#include <iostream>
using namespace std;
class Base {
public:
virtual void show() = 0;
};
class Derived : public Base {
public:
void show() override {
cout << "Derived";
}
};
int main() {
Derived obj;
obj.show();
return 0;
}
Options
-
A.
Base
-
B.
Derived
-
C.
Compilation error because Base is abstract
-
D.
More than one of the above
-
E.
None of the above
Correct Answer (Detailed Explanation is Below)
B.
Derived
Detailed Explanation
Correct Answer: Option BExplanation:Base is abstract, but Derived provides an implementation of the pure virtual function show(). Therefore, Derived is a concrete class and its object can be created. Calling obj.show() prints
Derived.