The following feature of C++ is an example of run time polymorphism

2026

The following feature of C++ is an example of run time polymorphism

  1. A.

    OPERATOR OVERLOADING

  2. B.

    POINTERS

  3. C.

    TEMPLATES

  4. D.

    VIRTUAL FUNCTION

Attempted by 60 students.

Show answer & explanation

Correct answer: D

Runtime polymorphism, also known as dynamic binding, occurs when a program determines which function implementation to call during execution rather than at compile time. This is achieved in C++ through virtual functions, which allow a derived class to override a base class function. When a pointer or reference to the base class points to an object of the derived class, calling the virtual function invokes the derived version at runtime. This mechanism enables flexible and extensible code design.\nIn contrast, operator overloading (Option A) is a compile-time feature where operators are redefined for user-defined types. Templates (Option C) also resolve at compile time through template instantiation, providing static polymorphism rather than dynamic. While pointers (Option B) are necessary tools for accessing objects, they do not inherently provide polymorphism without the use of virtual functions. Therefore, only virtual functions enable true runtime polymorphism in C++.

Explore the full course: Tpsc Assistant Technical Officer