Bird
0
0

Find the problem in this code snippet:

medium📝 Debug Q7 of 15
C Sharp (C#) - Inheritance
Find the problem in this code snippet:
class Base {
  public virtual void Print() {}
}
class Derived : Base {
  public override void Print(int x) {}
}
ADerived.Print must have same signature as Base.Print
BBase.Print must be abstract
CDerived.Print should be static
DNo problem, code is valid
Step-by-Step Solution
Solution:
  1. Step 1: Check method signatures for overriding

    Overriding requires method signatures to match exactly (name and parameters).
  2. Step 2: Identify signature mismatch

    Derived.Print has an int parameter, Base.Print has none, so this is method overloading, not overriding.
  3. Final Answer:

    Derived.Print must have same signature as Base.Print -> Option A
  4. Quick Check:

    Override requires matching signature [OK]
Quick Trick: Override methods must match base method signature exactly [OK]
Common Mistakes:
MISTAKES
  • Changing parameters breaks override
  • Confusing overloading with overriding
  • Assuming abstract needed for override

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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