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++ ?
Answer: B. ClassName(); — A C++ constructor must match the class name exactly and have no return type.
- A.
constructor ClassName();
- B.
ClassName();
- C.
void ClassName();
- D.
ClassName() {}
Attempted by 184 students.
Show answer & explanation
Correct answer: B
A C++ constructor must match the class name exactly and have no return type.
Loading lesson…