Bird
0
0

Identify the error in this C# code snippet:

medium📝 Debug Q6 of 15
C Sharp (C#) - Interfaces

Identify the error in this C# code snippet:

interface IA { void Display(); }
interface IB { void Display(); }
class Sample : IA, IB {
  public void Display() { Console.WriteLine("Display"); }
  void IA.Display() { Console.WriteLine("IA Display"); }
}
ANo error, code is valid
BCannot have both public and explicit Display implementations
CDisplay method must be private
DMissing implementation of IB.Display()
Step-by-Step Solution
Solution:
  1. Step 1: Analyze implementations

    The class provides explicit IA.Display() and public Display().
  2. Step 2: Verify interface satisfaction

    Public Display() implicitly implements IB.Display(); explicit handles IA.Display(). Code is valid.
  3. Final Answer:

    No error, code is valid -> Option A
  4. Quick Check:

    Mixing explicit and implicit implementations valid [OK]
Quick Trick: Public methods implicitly implement interfaces lacking explicit versions [OK]
Common Mistakes:
MISTAKES
  • Thinking explicit blocks public from implementing other interfaces
  • Expecting conflict between public and explicit for different interfaces
  • Believing all must be explicit or all implicit

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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