Course contentsShow
← Java
Lesson 210 of 2,8705. Methods and Function CallsFree lesson

Overloading by Parameter Order

Understand how different parameter ordering creates distinct method signatures.

Overloading by Parameter Order

What you'll learn: How rearranging parameter types in different orders creates distinct method signatures that Java treats as separate methods.

The Core Idea

You've learned that methods can be overloaded by having different numbers of parameters or different parameter types. Now here's a subtle but important detail: the order of parameter types matters too.

If you have a method that takes (int, String) and another that takes (String, int), Java sees these as completely different signatures—even though they contain the same types. The sequence in which parameters appear is part of what makes a method unique.

Why Order Creates Distinct Signatures

Think of it like giving directions: "Turn left, then right" is fundamentally different from "Turn right, then left"—same actions, different order, different destination.

public class Calculator {
    // First version: int first, then String
    public void display(int value, String label) {
        System.out.println(label + ": " + value);
    }
    
    // Second version: String first, then int
    public void display(String label, int value) {
        System.out.println(label + " = " + value);
    }
}

When you call display(42, "Score"), Java invokes the first method. When you call display("Score", 42), Java invokes the second. The compiler distinguishes them by matching the argument order exactly.

Practical Consideration

While this is technically valid overloading, it can confuse developers. If both methods do similar things, consider using different method names instead to make your intent clearer.

Key Takeaway: Parameter order is part of the method signature—method(int, String) and method(String, int) are two distinct, overloadable methods in Java.