Bird
0
0

You have interfaces IA and IB both with a method Execute(). You want a class Worker to implement both but have different behaviors for each. How should you implement this?

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

You have interfaces IA and IB both with a method Execute(). You want a class Worker to implement both but have different behaviors for each. How should you implement this?

ACreate two separate classes for IA and IB
BImplement one public Execute method for both interfaces
CUse inheritance instead of interfaces
DUse explicit interface implementation for both Execute methods
Step-by-Step Solution
Solution:
  1. Step 1: Understand requirement for different behaviors

    To have different behaviors for the same method name from two interfaces, explicit implementation is needed.
  2. Step 2: Apply explicit interface implementation

    Implement IA.Execute() and IB.Execute() explicitly to provide separate method bodies.
  3. Final Answer:

    Use explicit interface implementation for both Execute methods -> Option D
  4. Quick Check:

    Different behaviors = explicit interface implementation [OK]
Quick Trick: Explicit implementation allows method name reuse with different bodies [OK]
Common Mistakes:
MISTAKES
  • Using one public method for both interfaces
  • Trying inheritance to solve interface method conflicts
  • Splitting into multiple classes unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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