Utilizor
Contact Us

Java Method Overloading

Multiple methods with the same name.

Examples

Overloading Example

Two methods with the same name but different types.

public class Main {
  static int plusMethod(int x, int y) {
    return x + y;
  }
  
  static double plusMethod(double x, double y) {
    return x + y;
  }

  public static void main(String[] args) {
    int myNum1 = plusMethod(8, 5);
    double myNum2 = plusMethod(4.3, 6.26);
    System.out.println("int: " + myNum1);
    System.out.println("double: " + myNum2);
  }
}

Test Your Knowledge

Java Quiz

No quiz available for this topic yet.