Bird
0
0

Given interfaces:

hard🚀 Application Q9 of 15
C Sharp (C#) - Interfaces
Given interfaces:
interface IAlpha { void DoWork(); }
interface IBeta { void DoWork(); }
How can a class implement both interfaces and provide different implementations for each DoWork method?
ARename one method in the class
BImplement one method and it works for both interfaces
CUse explicit interface implementation for each method
DCannot implement both interfaces with same method name
Step-by-Step Solution
Solution:
  1. Step 1: Understand explicit interface implementation

    Allows class to implement interface methods separately even if names clash.
  2. Step 2: Apply explicit implementation syntax

    Use InterfaceName.MethodName() syntax to implement each method distinctly.
  3. Final Answer:

    Use explicit interface implementation for each method -> Option C
  4. Quick Check:

    Explicit implementation resolves method name conflicts [OK]
Quick Trick: Use explicit interface methods to separate same-named methods [OK]
Common Mistakes:
MISTAKES
  • Assuming one method covers both interfaces
  • Trying to rename interface methods in class
  • Believing it's impossible to implement both

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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