Table of contents
1.
Introduction 
2.
What is Method Overloading?
3.
Different Ways of Method Overloading in Java
3.1.
1. By changing the data type of parameters
3.2.
2. By changing the number of parameters
3.3.
3. By changing the sequence/order of parameters
4.
Advantages and Disadvantages of Method Overloading in Java
4.1.
Advantages of Method Overloading in Java
4.2.
Disadvantages of Method Overloading in Java
5.
Frequently Asked Questions
5.1.
What is method overriding in Java?
5.2.
What is the real-time use of method overriding?
5.3.
Does Java support Operator Overloading?
5.4.
What is the difference between Overloading and Overriding?
6.
Conclusion
Last Updated: Sep 19, 2025
Medium

Method Overloading in Java with Examples

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction 

Java is an object-oriented class-based programming language used in Front-end and Back-end. It is used to develop mobile applications, web applications, games, GUI applications, etc. It contains classes, methods, and objects encapsulated as a unit. Java is a platform-independent programming language. It can be used anywhere independent of the systems because it is compiled into bytecodes that can be run on any Java Virtual Machine(JVM).  

Method Overloading in Java

What is Method Overloading?

A program should be efficient and less complex. Suppose you need to perform any computation or operation more than once in a program with different inputs. It is difficult to write different methods multiple times with different parameters as it might confuse the other programmers. So, to avoid ambiguity, we use method overloading with the same method names and different parameters. It lets us know that the methods are the same and have the same functionality.

The methods inside Java contain the logic/ functionality to execute the program. There can be multiple methods inside a single class with any return types like int, float, void, String, etc. The technique of re-using the methods with the same name but different parameters is called Method overloading. The method's return type can be either be different or the same. 

Different Ways of Method Overloading in Java

  1. By changing the data type of parameters.
  2. By changing the number of parameters.
  3. By changing the sequence/order of parameters

Also see, Swap Function in Java

1. By changing the data type of parameters

We can overload any method by changing the data types of the parameters we send while invoking the method. Let’s consider an example with the same methods now.

Java Method Overloading Implementation with Code Example

class MethodOverloadingExample {

   static int addition(int x, int y) {
      return x + y;
   }

   static double addition(int x, double y) {
      return x + y;
   }

   public static void main(String[] args) {
      int a = addition(8, 8);
      double b = addition(4, 5.2);
      System.out.println("addition of integers: " + a);
      System.out.println("addition of double values: " + b);
   }
}
You can also try this code with Online Java Compiler
Run Code


We created a class MethodOverloadingExample in the above example containing the method addition with different return types. We invoked the method addition from the main method with different parameters of int and double.

Output

addition of integers: 16
addition of integers and double values: 9.2

You can also find the output of this java compiler code here.

2. By changing the number of parameters

We can overload any method by changing the number of parameters we send while invoking the method. Let’s learn about overloading by changing the number of parameters now.

Java Method Overloading Implementation with Code Example:

class MethodOverloadingExample {

   static int addition(int x, int y, int z) {
      return x + y + z;
   }
   
   static int addition(int x, int y) {
      return x + y;
   }

   public static void main(String[] args) {
      int a = addition(8, 2, 5);
      double b = addition(4, 5);
      System.out.println("addition of 3 integers: " + a);
      System.out.println("addition of 2 integers: " + b);
   }
}
You can also try this code with Online Java Compiler
Run Code


We created a class MethodOverloadingExample in the above example that contains the method addition with the same return types but different number of parameters. We invoked the method addition from the main method with two and three parameters, respectively.

Output

addition of 3 integers: 15
addition of 2 integers: 9 

3. By changing the sequence/order of parameters

We can overload any method by changing the data types of the parameters we send while invoking the method. 

Java Method Overloading Implementation with Code Example:

class MethodOverloadingExample {

   static double addition(double x, int y) {
      return x + y;
   }

   static double addition(int x, double y) {
      return x + y;
   }

   public static void main(String[] args) {
      int a = addition(5.2, 8);
      double b = addition(4, 5.2);
      System.out.println("addition of double and int: " + a);
      System.out.println("addition of int and double: " + b);
   }
}
You can also try this code with Online Java Compiler
Run Code


We created a class MethodOverloadingExample in the above example containing the method addition with the same return types, but the order of parameters is different. We invoked the method addition from the main method with different parameters of int and double.

Output

addition of double and int: 13.2
addition of double and int: 9.2

Advantages and Disadvantages of Method Overloading in Java

Method Overloading in Java is a key feature of polymorphism in Java, allowing multiple methods with the same name but different parameters. It enhances Java code reusability and simplifies API design, making code more readable and maintainable. However, while method overloading offers several benefits, it also has certain limitations, including Java method resolution complexities and potential Java performance overhead.

Advantages of Method Overloading in Java

  • Improves Code Readability and Maintainability: Overloading helps developers use a single method name for different functionalities, making the code more intuitive and easy to maintain.
  • Enhances Java Code Reusability: Instead of creating multiple method names for similar operations, overloading allows reusing the same method name, reducing redundancy and improving efficiency.
  • Simplifies Java API Design: Many Java APIs leverage method overloading to provide flexible interfaces, making libraries and frameworks more user-friendly. For example, System.out.println() is overloaded to handle various data types.
  • Supports Polymorphism in Java: Overloading is a form of compile-time polymorphism, allowing methods to behave differently based on their parameters, improving code flexibility.
  • Facilitates Better Method Resolution in Java: Java automatically determines the appropriate overloaded method at compile time, reducing runtime errors and ensuring efficient execution.

Disadvantages of Method Overloading in Java

  • Increases Java Performance Overhead: Overloading creates multiple method signatures, which increases memory consumption and may introduce slight performance overhead in method resolution.
  • Potential Confusion for Developers: If not used carefully, overloading can lead to ambiguity, especially when dealing with methods with similar parameter types, making debugging more complex.
  • Complex Java Method Resolution: Java’s compiler determines the most suitable overloaded method at compile-time, but implicit type conversions and autoboxing can sometimes lead to unexpected results.
  • Not Truly Dynamic: Unlike method overriding, overloading is resolved at compile-time and does not support runtime polymorphism, limiting its flexibility in certain cases.
  • Overuse Can Lead to Reduced Code Clarity: Excessive method overloading may make the codebase harder to understand, especially for new developers working on large projects.

Frequently Asked Questions

What is method overriding in Java?

Method overriding in Java allows a subclass to provide a specific implementation of a method already defined in its superclass.

What is the real-time use of method overriding?

Method overriding is used in Java to achieve runtime polymorphism, allowing subclasses to tailor a specific behavior to fit their needs.

Does Java support Operator Overloading?

Unlike C++, Java doesn’t allow user-defined overloaded operators. Internally, Java overloads operators; for example, + is overloaded for concatenation. 

What is the difference between Overloading and Overriding?

Overloading is about the same function having different signatures. Overriding is about the same function, and the same signature but different classes connected through inheritance.

Conclusion

Method overloading in Java enhances code's readability and flexibility by allowing multiple methods with the same name but different parameters within the same class. It reduces the need for redundant method names, which leads to cleaner and more maintainable code. Overall, method overloading is a powerful feature in Java that enables developers to write efficient, reusable, and organized code, making it easier to manage and scale applications.

Recommended Readings:

  1. String Args in Java
  2. Why is Java Platform Independent 
  3. Solid Principles in java
  4. Conditional Statements in Java
  5. Hashcode Method in Java.
Live masterclass