Method Overloading - Important Notes
Method Overloading means creating multiple methods with the same name in the same
class but with different parameter lists.
It is also known as compile-time polymorphism.
Examples:
1. add() with different parameter types:
int add(int a, int b)
double add(double a, double b)
2. add() with different number of parameters:
int add(int a, int b, int c)
3. print() with different order of parameters:
void print(int x, String s)
void print(String s, int x)
Rules:
- Only parameter list must change (type, number, or order).
- Return type alone cannot overload a method.
- Java supports method overloading but not operator overloading (except + for Strings).