Which of the following can be used to create an abstract class in C++?

Asked In: BPSC TRE 1.0

Options

  • A. By using a pure virtual function in the class
  • B. By declaring an ordinary virtual function in the base class
  • C. By writing the virtual keyword after the class declaration
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

A. By using a pure virtual function in the class

Detailed Explanation

Correct Answer: Option A

Explanation:
A class becomes abstract when it declares or inherits at least one pure virtual function that has not been overridden with a concrete implementation. A pure virtual function is declared using = 0, for example: virtual void display() = 0;. An ordinary virtual function alone does not make a class abstract.