Q. Which of the following is the correct syntax for a constructor in C++?

  • (A) void Constructor() {}
  • (B) Constructor() {}
  • (C) Constructor(void) {}
  • (D) void constructor() {}
πŸ’¬ Discuss
βœ… Correct Answer: (B) Constructor() {}
Explanation: A constructor in C++ has the same name as the class and no return type.
Explanation by: Gopal Sharma
A constructor in C++ has the same name as the class and no return type.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
181
Total Visits
πŸ“½οΈ
2 y ago
Published
πŸŽ–οΈ
Gopal Sharma
Publisher
πŸ“ˆ
94%
Success Rate