Method Overloading
Prerequisites: Methods
Java allows several methods to share the same name as long as their parameter lists differ — this is called overloading, and is resolved entirely at compile time based on the argument types.
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;
}
Common mistakes
- Confusing this with overriding (a subclass replacing a parent method's implementation — same signature, different behavior, resolved at runtime). Overloading is about having multiple different signatures for the same name.