Solution
The correct answer is class A { virtual void show() = 0; };
Explanation:
To declare an abstract class in C++, you need to use at least one pure virtual function. A pure virtual function is declared by appending = 0 to the function declaration within the class.
- class A { virtual void show() = 0; };
- This statement correctly declares an abstract class because it defines show() as a pure virtual function.
- class A { void show() = 0; };
- This statement is incorrect because show() is not declared as virtual. Only pure virtual functions can be declared with = 0.
- class A { void show() {}; }
- This statement declares a normal member function. It does not declare the class as abstract.
- class A { show() = 0; };
- This statement is incorrect because the function show() must have a return type specified.
Conclusion:
The correct statement that declares an abstract class is: 1) class A { virtual void show() = 0; };