1.

Which among the following is correct?(a) void test(int x=0, int y, int z=0)(b) void test(int x=0, int=0)(c) void test(int x, int y=0)(d) void test(int x=’c, int y)I have been asked this question in an interview for job.This interesting question is from Default Arguments in chapter Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right choice is (c) void test(int x, int y=0)

To explain: The default arguments must be mentioned at LAST in the argument LIST. Also, the type of values assigned must match with the argument type. All the default arguments must be mentioned at last, none of the NORMAL arguments should COME in between the default arguments list.



Discussion

No Comment Found

Related InterviewSolutions