Bird
0
0

Find the problem in this code snippet: interface ITest { void Run() => Console.WriteLine("Run"); } class Test : ITest { public void Run(int x) => Console.WriteLine(x); }

medium📝 Debug Q7 of 15
C Sharp (C#) - Interfaces
Find the problem in this code snippet: interface ITest { void Run() => Console.WriteLine("Run"); } class Test : ITest { public void Run(int x) => Console.WriteLine(x); }
ANo problem; code compiles fine.
BInterface method cannot have default implementation.
CClass method should be private.
DClass does not override interface method due to different signature.
Step-by-Step Solution
Solution:
  1. Step 1: Compare interface and class method signatures

    Interface has Run() with no parameters; class has Run(int x) with one parameter.
  2. Step 2: Understand override requirements

    Class method is an overload, not an override due to signature mismatch. The default interface method is still used for parameterless calls. No compile or runtime error.
  3. Final Answer:

    Class does not override interface method due to different signature. -> Option D
  4. Quick Check:

    Method signature must match to override = A [OK]
Quick Trick: Method signatures must match exactly to override [OK]
Common Mistakes:
MISTAKES
  • Assuming overload overrides interface method
  • Believing default methods cannot exist
  • Thinking access modifier causes error here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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