Which of the following is used to make an Abstract class?
2015
Which of the following is used to make an Abstract class?
- A.
Making at least one member function as pure virtual function
- B.
Making at least one member function as virtual function
- C.
Declaring as Abstract class using virtual keyword
- D.
Declaring as Abstract class using static keyword
Attempted by 166 students.
Show answer & explanation
Correct answer: A
Correct answer: Making at least one member function a pure virtual function.
Explanation: In C++, a class is abstract if it declares at least one pure virtual function. A pure virtual function forces derived classes to provide an implementation and is declared using '= 0'.
Example: virtual void draw() = 0;
Effect: A class with a pure virtual function cannot be instantiated; it serves as a base class and derived classes must override the pure virtual functions to be concrete.
Why the other choices are incorrect:
Declaring a function as virtual alone does not make the class abstract; virtual functions typically have implementations and do not force the class to be abstract.
There is no language construct that marks a class abstract simply by using a 'virtual' keyword on the class itself; only member functions can be virtual.
The static keyword makes members belong to the class rather than instances; it has no role in making a class abstract.
A video solution is available for this question — log in and enroll to watch it.