Method overloading in Java

Method Overloading is a feature in which we can create more than one method having the same name and same class but their parameter lists are dissimilar.

Why method overloading?

Assume that you have to execute multiplication of the given numbers but there can be any number of arguments (let’s say either 2 or 3 arguments for simplicity).

In order to achieve this, you can create two methods num2(int, int) and num3(int, int, int) for two and three parameters correspondingly. Programmers may get puzzled as the behavior of both methods are same but they differ by name. However, The superior way to complete this task is by overloading methods. Also, depending upon the argument passed, one of the overloaded methods is called.

How to perform method overloading in Java?

Here are different ways to perform method overloading:

  1.      A number of parameters.
  2.      The data type of parameters.
  3.      The sequence of Data type of parameters.

Watch this on YouTube – You can also watch the video tutorial or keep reading the blog.

You can also subscribe to the official Pristine Tech School channel and learn various advanced topics with ease.

Way 1: Different Number of parameters in the argument list

method overloading


output of method overloading

Way 2: Difference in the data type of parameters

example of method overloading


output of program

Way 3: Overloading – Sequence of a data type of arguments

method overloading example


output of program

I hope this blog will help to explain the concept of Method overloading better. Let me know if we miss on something in the comment section below, we would love to hear from you.


Happy Programming!

2 thoughts on “Method overloading in Java

  1. Its good as your other posts : D, appreciate it for posting . “The rewards for those who persevere far exceed the pain that must precede the victory.” by Ted W. Engstrom.

  2. I simply desired to appreciate you again. I’m not certain the things I might have created without the tactics documented by you relating to such concern. It absolutely was an absolute frustrating scenario for me, however , being able to view the very well-written avenue you handled it made me to jump with contentment. Now i’m thankful for the guidance and as well , expect you realize what a powerful job that you are carrying out training others via your webblog. Most probably you’ve never come across all of us.

Leave a Reply

Your email address will not be published. Required fields are marked *