Bird
0
0

Find the problem in this code that prevents runtime polymorphism:

medium📝 Debug Q7 of 15
C Sharp (C#) - Polymorphism and Abstract Classes
Find the problem in this code that prevents runtime polymorphism:
class Base { public void Display() { Console.WriteLine("Base"); } } class Derived : Base { public override void Display() { Console.WriteLine("Derived"); } }
ABase method must be virtual to allow override
BDerived method should not use override keyword
CDisplay method must be static
DNo problem, code works fine
Step-by-Step Solution
Solution:
  1. Step 1: Check base method declaration

    Base class method Display is not marked virtual, so it cannot be overridden.
  2. Step 2: Understand override requirements

    Derived class tries to override, but base method must be virtual or abstract for this to work.
  3. Final Answer:

    Base method must be virtual to allow override -> Option A
  4. Quick Check:

    Virtual needed in base for override [OK]
Quick Trick: Base method must be virtual to enable overriding [OK]
Common Mistakes:
MISTAKES
  • Trying to override non-virtual methods
  • Ignoring virtual keyword in base class
  • Misusing override keyword without virtual base

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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