What is method overloading?

Asked 06-Dec-2019
Viewed 459 times

1 Answer


Method Overloading occurs when a class has many methods with the same name but distinct parameters . When we just need to do one operation, having the methods titled the same helps the program's readability.

If you define the method as a(int, int) for two parameters and b(int, int, int) for three parameters, it may be difficult for you and other programmers to grasp the behavior.

Overloading allows various methods to have the same name but different signatures, with the signature differing depending on the number of input arguments, the kind of input parameters, or both. Compile-time (or static) polymorphism is linked to overloading.

If the parameters of two or more methods in Java differ, they can have the same name (different number of parameters, different types of parameters, or both). Overloaded methods are the term for these types of methods, and method overloading is the term for this functionality.

Overloading methods are a better technique to achieve this goal. One of the overloaded methods is then called, depending on the argument given. This contributes to the program's readability.

If two or more methods in the same class take distinct parameters, they can have the same name. Method overloading is the term for this capability.

Overloading a method can be accomplished in one of two ways:
  • Increasing or decreasing the number of arguments
  • Changing the data type of arguments is another option.
If we merely modify the return type of methods, it is not method overloading. Differences in the number of parameters must exist.