Which among the following represents correct constructor?

Options

  • A. classname()
  • B. -classname()
  • C. -classname()
  • D. (classname

Correct Answer (Detailed Explanation is Below)

A. classname()

Detailed Explanation

Explanation:

In C++, a constructor:

  • Has the same name as the class

  • Does not have a return type (not even void)

  • Is used to initialize objects


So, the correct format of a constructor is:

✔ classname()

Other options are incorrect because:

  • Constructors do not start with -

  • They cannot have brackets without proper syntax

  • They must exactly match the class name

OOps! You are currently offline.