ODNYX.

Compile-time Polymorphism

Video Tutorial Coming Soon — Channel Production Underway

Compile-time polymorphism (also called static polymorphism) is resolved by the compiler before the program even runs. In Java, the most common example is method overloading — defining multiple methods with the same name but different parameter lists.

Tip: the compiler decides which overloaded method to call based on the argument types you pass in, at compile time — hence the name.

Method overloading

public 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;
    }
}

All three methods are named add, but they differ in either the number or the type of parameters. The compiler picks the right one based on how you call it:

Calculator calc = new Calculator();
calc.add(2, 3);       // calls add(int, int)
calc.add(2.5, 3.5);   // calls add(double, double)
calc.add(1, 2, 3);    // calls add(int, int, int)

Why it’s called “compile-time”

Because the Java compiler determines exactly which overloaded method to bind to each call while compiling your code — there’s no ambiguity or decision left to make at runtime.

What’s next

Next: Runtime Polymorphism, the other half of this topic — driven by method overriding instead of overloading.

📋 Object-Oriented Programming Interview Questions