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
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.