What is method overloading in Java - Example Tutorial

What is method overloading in Java
Method overloading in Java is a programming concept when programmer declares two methods of the same name but with different method signature, e.g. change in the argument list or change in the type of argument. method overloading is a powerful Java programming technique to declare a method which does a similar performance but with a different kind of input. One of the most popular examples of method overloading is System.out.println() method which is overloaded to accept all kinds of data types in Java. You have println() method which takes String, int, float,double or even char in output. All of those methods are collectively referred as an overloaded method in Java. The difference between method overloading and overriding is also a popular Java interview question. In next section, we will some important points about method overloading in Java and then a simple example of how to overload a method in Java.

Properties of method overloading in Java

1) Overloaded methods are bonded using static binding in Java. Which occurs during compile time i.e. when you compile Java program. During the compilation process, compiler bind method calls to the actual method.

2) Overloaded methods are fast because they are bonded during compile time and no check or binding is required during runtime.

3) Most important rule of method overloading in Java is that two overloaded methods must have a different signature.Here is an example of What does method signature means in Java:

1) A number of argument to a method is part of method signature.
2) Type of argument to a method is also part of method signature
3) Order of argument also forms part of method signature provided they are of different type.
4) The return type of method is not part of the method signature in Java.

Method Overloading Example in Java

What is method overloading in Java with Example
Here is a list of method and there corresponding overloaded method with reason that How they are overloaded :

Original method :
 public void  show(String message){

Overloaded method : number of argument is different
 public void  show(String message, boolean show){

Overloaded method : type of argument is different
 public void  show(Integer message){
Not a Overloaded method : only return type is different
 public boolean show(String message){
      return false;

In the summary method, overloading means multiple methods with the same name but with a different signature. remember return type is not part of the method signature. method overloading is also completely different from method overriding which is a similar concept and we will see in the next article. That's all on What is method overloading in Java, let me know if you have any question related to How to overload a method in Java.

Further Learning
SOLID Principles of Object-Oriented Design
Absolute Introduction to Object-Oriented Programming in Java
Java - Object-Oriented Programming [For Absolute Beginners]

Other Java programming and OOP tutorials You may like


  1. Method overloading in any programming language, including Java will work fine if:

    - the two variants have a different number of parameters
    - the two variants have the same number of parameters but the types are unrelated

    In both cases, the overloaded method should logically consist of the same name and operation, but with different kind of inputs.

    For example, this is fine:

    LocalTime.of(int hour, int minute)
    LocalTime.of(int hour, int minute, int second)

    as both the method are actually creating time but with different set of input, so name of() is valid and there is on confusion between these two methods.

    Here is another example, which is also fine:
    Bundle.of(String[] data)
    Bundle.of(Iterable data)

    (there is no possible confusion between the types, the overload method is providing flexible input handling for callers, both methods must perform the same logical task and that's why same name)

    But if you have the same number of parameters and related types, then it's a big problem. That should be avoided as it causes users great difficulty in figuring out which method is called
    If two overloaded methods actually behave differently, then they also fail the rule that overloads should be logically equivalent.

  2. hmm..it looks like the same parameters to,,i mean in the local time part.

    any other example?

  3. Thanks for this tutorial

    You told overloading example is System.out.println(). So can you explain different argument types in println() in detailed explanation is required.

  4. public Double add(int a, double b) {
    return a+b;

    public Double add(double a, int b) {
    return a+b;

    Is this method overloading or not?

  5. yes, as sequence of arguments are interchanged


Feel free to comment, ask questions if you have any doubt.