Function Overloading
You can have multiple functions with the same name as long as their parameter lists differ in number, type, or both. The compiler picks the right one based on the arguments.
int add(int a, int b) {
return a + b;
}
double add(double a, double b) {
return a + b;
}
int add(int a, int b, int c) {
return a + b + c;
}
The return type alone isn't enough to distinguish overloads โ the parameters must be different. This is called overload resolution.
Overloading makes your API consistent. Instead of addInt, addDouble, addThree, you just write add.