Which among the following represents correct constructor?
Options
- A. classname()
- B. -classname()
- C. -classname()
- D. (classname
A. classname()
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
Attempt Quiz Now:
BPSC Tre 4.0 OOPS Concepts Practice Set