Bird
0
0

Find the problem in this polymorphism example:

medium📝 Debug Q7 of 15
C Sharp (C#) - Polymorphism and Abstract Classes
Find the problem in this polymorphism example:
class Animal { public virtual string Speak() => "Animal"; }
class Cat : Animal { public new string Speak() => "Meow"; }
AAnimal.Speak() should not be virtual
BCat.Speak() hides Animal.Speak() instead of overriding
CCat.Speak() must be static
DNo problem, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Understand 'new' keyword effect

    'new' hides base method instead of overriding it, breaking polymorphism.
  2. Step 2: Identify correct approach

    To enable polymorphism, Cat.Speak() should use 'override' instead of 'new'.
  3. Final Answer:

    Cat.Speak() hides Animal.Speak() instead of overriding -> Option B
  4. Quick Check:

    'new' hides method, 'override' enables polymorphism [OK]
Quick Trick: 'override' enables polymorphism, 'new' hides methods [OK]
Common Mistakes:
MISTAKES
  • Using 'new' instead of 'override' for polymorphism
  • Thinking virtual keyword is unnecessary
  • Believing static methods can override instance methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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