Bird
0
0

Find the problem in this code:

medium📝 Debug Q7 of 15
C Sharp (C#) - Polymorphism and Abstract Classes
Find the problem in this code:
class Base {
    public virtual void Print() { }
}
class Derived : Base {
    public override void Print(int x) { }
}
AMethod signature mismatch; cannot override with different parameters.
BBase method should be abstract.
CDerived method should be virtual.
DNo problem; code is valid.
Step-by-Step Solution
Solution:
  1. Step 1: Compare method signatures

    Overriding requires exact signature match; Print() vs Print(int x) differ.
  2. Step 2: Identify signature mismatch error

    Derived method is not overriding but overloading; compiler error occurs due to override keyword with different signature.
  3. Final Answer:

    Method signature mismatch; cannot override with different parameters. -> Option A
  4. Quick Check:

    Override requires exact signature match [OK]
Quick Trick: Override needs exact method signature match [OK]
Common Mistakes:
MISTAKES
  • Changing parameters when overriding
  • Confusing overloading with overriding
  • Ignoring compiler errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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