What is compile-time polymorphism in Object-Oriented Programming (OOP)? Explain how it is achieved and illustrate the concept with a suitable code…

What is compile-time polymorphism in Object-Oriented Programming (OOP)? Explain how it is achieved and illustrate the concept with a suitable code example.

From the BUET MSC (CSE) October 2026 – Written exam, question 5 of 14.

Answers (1)

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

More from this paper