Bird
Raised Fist0

Why does C# use a virtual method dispatch mechanism instead of static method calls for virtual methods?

hard🧠 Conceptual Q10 of Q15
C Sharp (C#) - Polymorphism and Abstract Classes
Why does C# use a virtual method dispatch mechanism instead of static method calls for virtual methods?
ATo enable runtime polymorphism and call the correct override based on object type.
BTo improve compile-time performance by avoiding method lookups.
CTo prevent derived classes from overriding base methods.
DTo enforce method hiding instead of overriding.
Step-by-Step Solution
Solution:
  1. Step 1: Understand purpose of virtual dispatch

    Virtual dispatch allows the program to decide at runtime which method implementation to call based on the actual object type.
  2. Step 2: Contrast with static calls

    Static calls are fixed at compile-time and cannot support polymorphism, which is essential for flexible object-oriented design.
  3. Final Answer:

    To enable runtime polymorphism and call the correct override based on object type. -> Option A
  4. Quick Check:

    Virtual dispatch enables runtime polymorphism [OK]
Quick Trick: Virtual dispatch enables runtime method selection [OK]
Common Mistakes:
MISTAKES
  • Thinking virtual dispatch improves compile-time speed
  • Believing it prevents overriding
  • Confusing hiding with overriding

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes