1.

Which is the correct syntax for using default arguments with the constructor?(a) default constructorName(default int x=0)(b) constructorName(default int x=0)(c) constructorName(int x=0)(d) constructorName()This question was posed to me in unit test.I want to ask this question from Constructors Overloading in portion Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer» RIGHT answer is (c) constructorName(INT x=0)

To explain I would say: The constructors using the default arguments must initialize the arguments in the ARGUMENT LIST. This is to make the CONSTRUCTOR use the default value when no arguments are passed. If no arguments are listed then it is a default constructor.


Discussion

No Comment Found

Related InterviewSolutions