1.

Which constructor among the following will be called if a call is made like className(5,’a’);?(a) className(int x=5,char c=’a’);(b) int className(int x, char c, char d);(c) className(int x, char c, int y);(d) char className(char c,int x);I got this question by my school principal while I was bunking the class.The origin of the question is Constructors Overloading in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Correct answer is (a) className(int x=5,CHAR c=’a’);

Best explanation: The SYNTAX given is passing two PARAMETERS to the constructor CALL. One value is of integer type and another of character type. Hence the constructor with arguments of int and char type should be called. There is only one option that first accepts integer value and then a character value. Hence that constructor will be called.



Discussion

No Comment Found

Related InterviewSolutions