Skip to content
Justice Tech School

Method Overloading

Several methods can share a name if their parameter lists differ in number or type. The compiler picks the one that matches the call.

Example
public class Main {
  static int plus(int a, int b) { return a + b; }
  static double plus(double a, double b) { return a + b; }
  static String plus(String a, String b) { return a + b; }

  public static void main(String[] args) {
    System.out.println(plus(1, 2));
    System.out.println(plus(1.5, 2.5));
    System.out.println(plus("Java", "Script"));
  }
}

Result

3
4.0
JavaScript

Exercise

Overloaded methods share the same...

Methods can have the same  with different parameters

Quiz Test

What must differ between overloaded methods?

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