Multiple choice

Which of the following statements is TRUE with reference to 'Method Overloading'?

  1. All the methods must have different return values.

  2. All the methods must be declared in the base class and redeclared in the child class.

  3. All the methods must differ in arguments.

  4. The name of the arguments should be different.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

To overload a method we must keep some difference in their arguments. The difference in the arguments can be either in their numbers, orders or datatypes. For example, we can have two methods with the name sum(), first with two integer arguments and second with three arguments. If the arguments are same in number, datatype or order the compiler will throw an ambiguity error which will mean that it is not able to differentitate one method with the other. Example: void sum(int); void sum(int,int); void sum(double, int);