Which of the following is true regarding constructors in C++?
17 views
- A constructor cannot have any parameters.
- A constructor can be called explicitly using the class name. (Correct Answer)
- A constructor can return a value.
- A class can have only one constructor
Explanation
Correct answer: b) A constructor can be called explicitly using the class name.
Explanation: A constructor is a special member function of a class that is called when an object of that class is created. A constructor can have parameters and can be called explicitly using the class name to create an object. Option a) is false, as a constructor can have parameters. Option c) is false, as a constructor does not return any value. Option d) is false, as a class can have multiple constructors.