Bird
Raised Fist0

Which statement best describes when to use an interface instead of an abstract class in C#?

easy🧠 Conceptual Q11 of Q15
C Sharp (C#) - Interfaces
Which statement best describes when to use an interface instead of an abstract class in C#?
AUse an interface when you want to provide shared code to subclasses.
BUse an interface when unrelated classes share behavior but do not share code.
CUse an abstract class when unrelated classes share behavior but do not share code.
DUse an abstract class only when no methods need to be implemented.
Step-by-Step Solution
Solution:
  1. Step 1: Understand interfaces

    Interfaces define method signatures without implementation, so they are ideal for unrelated classes that share behavior but not code.
  2. Step 2: Understand abstract classes

    Abstract classes can provide shared code and force subclasses to implement certain methods, so they are better for related classes sharing code.
  3. Final Answer:

    Use an interface when unrelated classes share behavior but do not share code. -> Option B
  4. Quick Check:

    Interface = unrelated classes sharing behavior [OK]
Quick Trick: Interfaces = behavior only, abstract classes = shared code [OK]
Common Mistakes:
MISTAKES
  • Thinking abstract classes can't have implemented methods
  • Using abstract class for unrelated classes
  • Confusing interfaces as code providers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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