What is the effect of declaring a C++ class constructor as private?

Options

  • A. Objects of the class cannot normally be created directly from outside the class
  • B. The class automatically becomes abstract
  • C. The constructor becomes virtual
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

A. Objects of the class cannot normally be created directly from outside the class

Detailed Explanation

Answer: (A) Objects of the class cannot normally be created directly from outside the class

If a constructor is declared private, code outside the permitted member or friend access cannot directly call that constructor.

Therefore, a statement such as Test obj; may be rejected if the required constructor is private.

Private constructors are useful in certain designs, such as controlling object creation or implementing patterns where objects are created through a member function.

A private constructor does not automatically make a class abstract.