Which of the following is a correct syntax for declaring a constructor in C++ ?
2025
Which of the following is a correct syntax for declaring a constructor in C++ ?
- A.
constructor ClassName();
- B.
ClassName();
- C.
void ClassName();
- D.
ClassName() {}
Attempted by 64 students.
Show answer & explanation
Correct answer: B
A C++ constructor must match the class name exactly and have no return type.