Bird
Raised Fist0

Given two interfaces IX and IY both having method Process(), how can a class Worker implement both explicitly and allow calling Process() without casting?

hard🚀 Application Q15 of Q15
C Sharp (C#) - Interfaces
Given two interfaces IX and IY both having method Process(), how can a class Worker implement both explicitly and allow calling Process() without casting?
AUse inheritance instead of interfaces
BImplement explicit methods only, no public method needed
CImplement only one interface explicitly and the other implicitly
DImplement explicit methods and add a public method calling one interface method
Step-by-Step Solution
Solution:
  1. Step 1: Understand explicit implementation limits

    Explicit interface methods are accessible only via interface references, not directly on class objects.
  2. Step 2: Provide public method to call explicit method

    To call Process() without casting, class must have a public method that internally calls one explicit interface method.
  3. Final Answer:

    Implement explicit methods and add a public method calling one interface method -> Option D
  4. Quick Check:

    Public wrapper calls explicit method = direct access [OK]
Quick Trick: Add public method calling explicit interface method [OK]
Common Mistakes:
MISTAKES
  • Expecting explicit methods callable without casting
  • Implementing only one interface explicitly
  • Ignoring need for public wrapper method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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