1.

Which among the following is true?(a) The constructors overloading can be done by using different names(b) The constructors overloading can be done by using different return types(c) The constructors can be overloaded by using only one argument(d) The constructors must have the same name as that of classThis question was posed to me during an interview.Origin of the question is Constructors Overloading in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Correct option is (d) The constructors MUST have the same name as that of class

To EXPLAIN I would say: The constructors must have the same name as that of the class name. This is mandatory because only the constructor FUNCTIONS doesn’t have any return TYPE. ALSO, for overloading all the functions must have the same name.



Discussion

No Comment Found

Related InterviewSolutions