OOPs HandbookPolymorphism Internals: Compile-Time vs Runtime, Virtual Functions & VTables
The 4 PillarsIntermediate
9 min read

Polymorphism Internals: Compile-Time vs Runtime, Virtual Functions & VTables

Early binding vs late binding, operator/method overloading vs overriding, and pure virtual functions.

TM
TestMeMan SDE Curriculum
Updated Sept 2026
Verified for FAANG Interviews
FROM TESTMEMAN•TestMeMan

Mock tests for SSC, Banking, Railways, UPSC & state exams

Real exam pattern, negative marking and a worked solution for every question.

Sponsored Publisher Placement•
ID: ad-top-leaderboard
Executive Summary

Polymorphism allows code to behave differently depending on runtime context or method signatures. It is the primary engine behind clean, extensible software architecture.

1. Compile-Time vs Runtime Polymorphism#

• Compile-Time Polymorphism (Static / Early Binding): The function call is linked to its executable code at compilation time. The compiler inspects the arguments and resolves the call statically. Examples: Method Overloading and Operator Overloading.

• Runtime Polymorphism (Dynamic / Late Binding): The actual implementation executed is resolved during program runtime based on the actual object type in memory. Example: Method Overriding.

2. Deep Comparison: Method Overloading vs Method Overriding#

This is the single most tested question in technical interviews (Question 13 & Tricky Question 3):

CharacteristicMethod OverloadingMethod Overriding
Binding TimeCompile-Time (Static / Early Binding)Runtime (Dynamic / Late Binding)
ScopeOccurs within the SAME classOccurs between Superclass and Subclass
Method SignatureSame method name, but DIFFERENT parameter count, types, or orderEXACT SAME method name, return type, and parameter list
Return Type RuleReturn type CANNOT differentiate overloaded methods by itselfReturn type must be identical (or covariant)
Private/Static MethodsCan overload private and static methodsCANNOT override private or static methods (static creates method hiding)
Sponsored ContentTestMeMan

Practise placement aptitude on the real test pattern

TCS NQT, Infosys, Wipro, Accenture and Cognizant style mocks with section-wise analysis.

3. Virtual Functions & Pure Virtual Functions#

• Virtual Function: A member function in a base class declared with the `virtual` keyword in C++. It tells the compiler to look up the function in the virtual method table (vtable) at runtime rather than binding it statically. In Java, all non-static, non-private, non-final methods are virtual by default!

• Pure Virtual Function: A virtual function with no implementation body in the base class (syntax: `virtual void render() = 0;`). A class containing at least one pure virtual function becomes an Abstract Class and cannot be instantiated.

1class Shape {
2public:
3 // Pure Virtual Function (Abstract)
4 virtual void draw() = 0;
5
6 // Regular Virtual Function
7 virtual double area() { return 0.0; }
8};
9
10class Circle : public Shape {
11public:
12 void draw() override {
13 std::cout << "Drawing Circle\n";
14 }
15};

4. Operators That CANNOT Be Overloaded in C++#

Question 24 from the interview sheet: "Name the operators that cannot be overloaded in C++."

The 5 operators that cannot be overloaded are:

  • 1. Scope Resolution Operator (::)
  • 2. Ternary / Conditional Operator (? :)
  • 3. Member Access or Dot Operator (.)
  • 4. Pointer to Member Operator (.*)
  • 5. sizeof operator (and typeid in modern C++)
Why Can’t These Be Overloaded?

C++ creator Bjarne Stroustrup explained that overloading operators like `.` or `::` would fundamentally alter C++ syntax parsing, leading to ambiguous expressions and breaking compiler memory lookup guarantees.

Test Your Concept Mastery

Verify your retention on: Polymorphism Internals: Compile-Time vs Runtime, Virtual Functions & VTables

Diagnostic Check
Question 1 of 1
Which operator CANNOT be overloaded in C++?
Ready for a full proctored assessment?

Take a free quick test on the real exam pattern, with a worked solution for every question.

Launch Mock Test