Java OCA OCP Practice Question 422

Question

Which of the following are true regarding overloading of a method?

Select 1 option

  • A. An overloading method must have a different parameter list and same return type as that of the overloaded method.
  • B. If there is another method with the same name but with a different number of arguments in a class then that method can be called as overloaded.
  • C. If there is another method with the same name and same number and type of arguments but with a different return type in a class then that method can be called as overloaded.
  • D. An overloaded method means a method with the same name and same number and type of arguments exists in the super class and sub class.


Correct Option is  : B

Note

For overloading a method, the "signature" of the overloaded methods must be different.

A method signature includes method name and the number and type of arguments that it takes.

If the parameter list of the two methods with the same name are different either in terms of number or in terms of the types of the parameters, then they are overloaded.

For example:

Method m1 is overloaded if you have two methods:

void m1 (int k); and 
void m1 (double d);  

or if you have:

void m1 (int k); and 
void m1 (int k, double d);  

return type is not considered a part of the method signature.

D. is talking about overriding and not overloading.




PreviousNext

Related