Java – Method Overloading

PREV     NEXT

  • If a class contains two or more methods with the same name, it is called method overloading.
  • It is used to achieve static polymorphism.
  • Binding of the method to its method call, is done in the compile time itself and hence it is called static binding or early binding.
  • The overloaded methods can differ by the number of arguments or argument type or sequence of the arguments.
  • The overloading method can be present in the same class or in subclasses of current class also.
    The difference should be only in the types and count of parameters, not in the method return types.

Example:

COMPILE & RUN

Output:

Addition of the 2 numbers is:12

Addition of the 2 numbers is:9.2


Addition of the 3 numbers is:15

PREV     NEXT

Share this website !!!
Facebook Twitter Linkedin