Java Overloading

Overloaded method gives you an option to use the same method name in a class but with different argument.

Method overloading is a controversial language feature, especially in the context of Object Oriented languages, where its interaction with overriding may lead to confusing semantics. One of the main arguments against overloading is that it can be abused by assigning the same identity to conceptually different methods

Overloading Method Rules
There are some rules associated with overloaded method.

Overloaded methods

  • Must change the argument list
  • Can change the return type
  • Can change the access modifier(Broader)
  • Can declare new or broader checked exception
  • A method can be overloaded in Class or in SubClass.

Overloading Method Example

Invoking Overloaded Method
Out of several available overloaded method which method to invoke is based on the arguments.

First call will execute the first method and second will execute the second method.