Method overloading rules - Core Java

Q.  The following two rules are defined by?
      1. The parameters may differ in their type or number, or in both.
      2. They may have the same or different return types.

- Published on 10 Jul 15

a. Method overloading
b. Method overriding
c. Constructor overloading
d. None of the above

ANSWER: Method overloading
 

    Discussion

  • Rupesh Bharuka   -Posted on 29 Sep 16
    Method overloading is a static polymorphism which can also be said as compile time polymorphism. It can be used when we identify the purpose is same but the type is different.

    Eg. If I want to perform addition of 2 numbers then first time I will consider 2 numbers are of type int but later I thought user may enter float or double values also then I will overload a method.

    In method overloading method name will remain same but parameters have to be different. Sequence of parameters also matters a lot.

    Return type doesn't matters it may be same or different according to the requirement.

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)