Bird
0
0

Given interfaces IX and IY with method Process(), and a class Handler implementing both with explicit implementations, how can you call IY.Process() on an instance of Handler?

hard🚀 Application Q9 of 15
C Sharp (C#) - Interfaces

Given interfaces IX and IY with method Process(), and a class Handler implementing both with explicit implementations, how can you call IY.Process() on an instance of Handler?

ACast the instance to IY and call Process()
BCall Process() directly on the Handler instance
CUse reflection to invoke Process()
DCannot call explicit interface methods
Step-by-Step Solution
Solution:
  1. Step 1: Understand explicit interface implementation

    Explicit interface methods are not accessible via class instance directly.
  2. Step 2: Use casting to interface type

    Casting the instance to IY allows calling IY.Process() explicitly implemented method.
  3. Final Answer:

    Cast the instance to IY and call Process() -> Option A
  4. Quick Check:

    Explicit methods require interface cast to call [OK]
Quick Trick: Cast to interface to call explicit methods [OK]
Common Mistakes:
MISTAKES
  • Calling explicit methods directly on class instance
  • Thinking reflection is needed
  • Believing explicit methods are inaccessible

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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