0Pricing
Java Academy · Lesson

Method Overloading Rules

Understand how Java resolves overloaded methods and common ambiguity pitfalls.

Method Overloading Rules

Method overloading lets you define multiple methods with the same name but different parameter lists. Java selects the best match at compile time using precise resolution rules.

What is Overloading?

Overloaded methods share a name but differ in parameter count, type, or order. The return type alone is NOT sufficient to overload.

class Calculator {
    int add(int a, int b)     { return a + b; }
    double add(double a, double b) { return a + b; }
    int add(int a, int b, int c)   { return a + b + c; }

    // compile error — same signature, different return type only:
    // long add(int a, int b) { return a + b; }
}

Calculator calc = new Calculator();
System.out.println(calc.add(1, 2));       // 3 (int)
System.out.println(calc.add(1.5, 2.5));   // 4.0 (double)
System.out.println(calc.add(1, 2, 3));    // 6 (3-arg)

All lessons in this course

  1. Method Overloading Rules
  2. Varargs Parameters
  3. Static Fields and Constants
  4. Utility Classes and Static Factory Methods
← Back to Java Academy