Skip to content
Justice Tech School

Method Overloading

Methods may share a name with different parameters.

Example
public class Main {
  static int add(int a, int b) { return a + b; }
  static double add(double a, double b) { return a + b; }
  static int add(int a, int b, int c) { return a + b + c; }
  public static void main(String[] args) {
    System.out.println(add(1, 2) + " " + add(1.5, 2.5) + " " + add(1, 2, 3));
  }
}

Result

3 4.0 6

Exercise

Same name different params.

Overloading changes the 

Quiz Test

What must differ in overloads?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.