Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

51.

Which among the following is a wrong call to the function void test(int x, int y=0, int z=0)?(a) test(5,6,7);(b) test(5);(c) test();(d) test(5,6);This question was posed to me during an interview for a job.Question is from Default Arguments in division Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right ANSWER is (c) test();

The EXPLANATION is: The function must be PASSED with at least one argument. There is two default arguments and one NORMAL argument which must be passed with some value. Hence the third call to the function is wrong as it doesn’t pass even a SINGLE parameter to the func

52.

What function will be called with the independent syntax “test(5,6,7);”?(a) void test(int x, int y)(b) void test(int x=0, int y, int z)(c) int test(int x=0, y=0, z=0)(d) void test(int x, int y, int z=0)This question was posed to me in an internship interview.Asked question is from Default Arguments topic in chapter Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

The CORRECT choice is (d) void test(int x, int y, int z=0)

To explain: There are three arguments that are getting passed to the function test(). Only the last option have all the default argument at last in the argument list. And the total number of the arguments is three. The third option is wrong because the return type is int and the SYNTAX given is INDEPENDENT which means it doesn’t return any VALUE.

53.

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.

54.

If a function have all the default arguments but still some values are passed to the function then ______________(a) The function will use the values passed to it(b) The function will use the default values as those are local(c) The function can use any value whichever is higher(d) The function will choose the minimum valuesI had been asked this question in an internship interview.This intriguing question originated from Default Arguments topic in division Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Correct choice is (a) The FUNCTION will use the values PASSED to it

Easiest EXPLANATION - The function will use the values passed EXPLICITLY to it. The default values will be ignored. The default values are used only in CASE the values are not passed explicitly to the function.

55.

Which among the following function can be called without arguments?(a) void add(int x, int y=0)(b) void add(int=0)(c) void add(int x=0, int y=0)(d) void add(char c)I got this question during an online interview.My question is taken from Default Arguments in division Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer» RIGHT choice is (c) void add(INT x=0, int y=0)

The best explanation: For the FUNCTION to be called WITHOUT arguments, EITHER it must have zero arguments or it must have all the default arguments. Here the function in option void add(int x=0, int y=0) have all the default arguments and hence can be called directly with zero argument.
56.

If a member function have to be made both zero argument and parameterized constructor, which among the following can be the best option?(a) Two normal and one default argument(b) At least one default argument(c) Exactly one default argument(d) Make all the arguments defaultThis question was posed to me at a job interview.Question is from Default Arguments topic in division Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer» RIGHT answer is (d) Make all the arguments default

Explanation: All the arguments MUST be made default. This will make sure that none of the arguments are mandatory to be passed. Which in turn MEANS that the function can work WITHOUT any ARGUMENT and can be passed with arguments too.
57.

Which is the correct condition for the default arguments?(a) Those must be declared as last arguments in argument list(b) Those must be declared first in the argument list(c) Those can be defined anywhere in the argument list(d) Those are declared inside the function definitionI have been asked this question in an internship interview.Asked question is from Default Arguments topic in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right option is (a) Those must be declared as last arguments in ARGUMENT list

For EXPLANATION: The DEFAULT arguments must be declared at last in the argument list. This is to ensure that the arguments doesn’t CREATE ambiguity. The normal arguments should be passed first.

58.

What are default arguments?(a) Arguments which are not mandatory to be passed(b) Arguments with default value that aren’t mandatory to be passed(c) Arguments which are not passed to functions(d) Arguments which always take same data valueI got this question in final exam.My enquiry is from Default Arguments in chapter Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

The correct answer is (b) ARGUMENTS with default VALUE that aren’t mandatory to be passed

The best EXPLANATION: The arguments which are assigned with some default value. Since some value is already GIVEN, it is not mandatory to pass those arguments. They can be used directly.