Bird
0
0

Why might a developer choose to seal a method in a class hierarchy?

hard🧠 Conceptual Q10 of 15
C Sharp (C#) - Inheritance
Why might a developer choose to seal a method in a class hierarchy?
ATo prevent further overriding and ensure consistent behavior.
BTo allow multiple overrides in subclasses.
CTo make the method abstract and force implementation.
DTo allow the method to be called only from the base class.
Step-by-Step Solution
Solution:
  1. Step 1: Understand purpose of sealing methods

    Sealing a method stops subclasses from changing its behavior.
  2. Step 2: Consider design reasons

    This ensures consistent behavior and prevents accidental overrides.
  3. Final Answer:

    To prevent further overriding and ensure consistent behavior. -> Option A
  4. Quick Check:

    Sealing method purpose = prevent overrides [OK]
Quick Trick: Seal methods to lock behavior and avoid unintended overrides [OK]
Common Mistakes:
MISTAKES
  • Thinking sealing allows more overrides
  • Confusing sealed with abstract methods
  • Believing sealing restricts method calls

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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