1.

Which among the following can be used in place of default constructor?(a) constructorName(int x, int y=0)(b) constructorName(int x=0, int y=0)(c) constructorName(int x=0, int y)(d) constructorName(int x, int y)I got this question by my school principal while I was bunking the class.This intriguing question originated from Constructors Overloading topic in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

The CORRECT answer is (B) CONSTRUCTORNAME(int x=0, int y=0)

Easiest explanation - For a parameterized constructor to be used as a default constructor, it must have all the default arguments. This MAKES the constructor to have optional arguments which are not mandatory to be passed.



Discussion

No Comment Found

Related InterviewSolutions