Bird
Raised Fist0

Why does C# allow interfaces to have default implementations starting from recent versions?

hard🧠 Conceptual Q10 of Q15
C Sharp (C#) - Interfaces

Why does C# allow interfaces to have default implementations starting from recent versions?

ATo replace abstract classes completely
BTo allow interfaces to store state like classes
CTo allow interfaces to be instantiated
DTo enable adding new methods without breaking existing implementations
Step-by-Step Solution
Solution:
  1. Step 1: Understand default interface methods purpose

    They allow adding new methods with default code so existing classes don't break.
  2. Step 2: Evaluate other options

    A is false as they complement abstract classes; B is false because interfaces still cannot store state; D is false because interfaces cannot be instantiated.
  3. Final Answer:

    To enable adding new methods without breaking existing implementations -> Option D
  4. Quick Check:

    Default methods = backward compatibility [OK]
Quick Trick: Default methods prevent breaking old code when interfaces evolve [OK]
Common Mistakes:
MISTAKES
  • Thinking interfaces store data
  • Confusing interfaces with classes
  • Assuming interfaces can be instantiated

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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