Learn Java
import com.learnjava.methods.MethodOverloading;

Method Overloading in Java

@Concept

Method overloading lets several methods share the same name as long as their parameter lists differ — in count, in type, or both — with the compiler picking which one to actually call based on the arguments supplied at each call site. add(int, int) and add(double, double) can coexist as two entirely separate methods that happen to share a name, and Java resolves which one a given call means at compile time, not at runtime.

The return type alone is never enough to distinguish overloads — two methods with identical parameter lists but different return types are a compile error, since the compiler has no way to choose between them based on the call site alone, before it even knows what the caller intends to do with the result.

@HowItWorks
1

Same name, different parameters

Overloaded methods share a name but differ in their parameter list's count, types, or both.

2

Resolved at compile time

The compiler picks which overload a given call means based on the argument types supplied, before the program ever runs.

3

Return type alone isn't enough

Two methods with identical parameters but different return types cannot coexist — that's a compile error, not a valid overload.

4

Widening applies during resolution

An int argument can match a method expecting a double parameter through automatic widening if no exact int overload exists.

5

A common, everyday example

System.out.println itself is overloaded dozens of times, once for each type it can print directly.

@Example
public class OverloadDemo {
static int add(int a, int b) {
return a + b;
}
 
static double add(double a, double b) {
return a + b;
}
 
public static void main(String[] args) {
System.out.println(add(2, 3));
System.out.println(add(2.5, 3.5));
}
}
Output
5
6.0
1add(2, 3) supplies two int arguments, so the compiler selects the int-parameter version of add.
2add(2.5, 3.5) supplies two double arguments instead, matching the other overload entirely.
3Both calls run entirely different method bodies despite sharing the name add.
4The two println calls each print once — an int result, then a double result.
@UseCases
Offering several convenient ways to call logically the same operation, like println for many types
Writing a constructor that can be called with different combinations of initial values
Understanding why a call resolves to one specific overload instead of another
Recognizing why two methods can't be overloaded on return type alone

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in Java yourself — building beats watching.