How many major kinds of polymorphism does C++ support? Distinguish by when binding happens relative to compile time.

Difficulty: Easy

Correct Answer: 2

Explanation:


Introduction:
Polymorphism means “many forms” — the ability for the same interface to exhibit different behaviors. In C++, polymorphism is broadly categorized by whether it is resolved at compile time or at runtime.


Given Data / Assumptions:

  • Language: C++.
  • We consider standard categories, not niche taxonomies.
  • Examples include function/operator overloading and virtual dispatch.


Concept / Approach:
C++ supports two principal kinds: compile-time (static) polymorphism and runtime (dynamic) polymorphism. Compile-time includes templates, function overloading, and operator overloading. Runtime uses virtual functions and dynamic dispatch via base-class interfaces.


Step-by-Step Solution:
1) Identify compile-time mechanisms: templates, overload sets, inline substitution decided by the compiler.2) Identify runtime mechanisms: virtual functions resolved through vtables at execution time.3) Count distinct categories: 2.4) Map to the answer: “2”.


Verification / Alternative check:
Consult common C++ texts that divide polymorphism into static and dynamic; examples demonstrate decisions made either during compilation or at runtime.


Why Other Options Are Wrong:
1: ignores one of the two major forms.3 or 4: overcounts by splitting subtypes beyond the commonly accepted categories.


Common Pitfalls:
Confusing inheritance with polymorphism; inheritance enables runtime polymorphism but is not itself a separate kind. Also, templates are compile-time, not runtime.


Final Answer:
2

More Questions from OOPS Concepts

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion