Compile-time (static) polymorphism means one name with several forms, where the compiler decides which form to call from the arguments — before the program runs (static binding).
It is achieved by method / function overloading (same name, different parameter lists) and, in C++, operator overloading. Return type alone cannot distinguish overloads.
class Calculator {
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; }
}
Calculator c = new Calculator();
c.add(2, 3); // add(int, int) -> 5
c.add(2.5, 1.5); // add(double, double) -> 4.0
c.add(1, 2, 3); // add(int, int, int) -> 6
Contrast: run-time polymorphism is method overriding, resolved through the object’s actual type while the program runs.
— rhs