1.

If a constructors should be capable of creating objects without argument and with arguments, which is a good alternative for this purpose?(a) Use zero argument constructor(b) Use constructor with one parameter(c) Use constructor with all default arguments(d) Use default constructorI had been asked this question in homework.My enquiry is from Constructors Overloading topic in portion Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Correct OPTION is (C) Use constructor with all default arguments

The best I can explain: The constructor should use all the default arguments. This will ALLOW the constructor to be called even if no arguments are passed. And if arguments are passed, those will be accepted INSTEAD of the default values.



Discussion

No Comment Found

Related InterviewSolutions