Which statement about constructors of abstract classes in C++ is correct?

class Base
{
public:
    Base()
    {
        cout << "Base";
    }

    virtual void show() = 0;
};
                        

Options

  • A. An abstract class cannot have a constructor.
  • B. An abstract class can have a constructor.
  • C. A constructor makes the class non-abstract.
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

B. An abstract class can have a constructor.

Detailed Explanation

Answer: (B) An abstract class can have a constructor.

An abstract class can have a constructor even though an object of the abstract class cannot be created directly.

The constructor of the abstract base class can be executed as part of constructing an object of a derived class.

Having a constructor does not remove the abstract nature of the class. The class remains abstract as long as it contains at least one pure virtual function.