Bird
0
0

Given a base class with a virtual method, how can you allow a derived class to override it but prevent any further overrides in subclasses?

hard🚀 Application Q8 of 15
C Sharp (C#) - Inheritance
Given a base class with a virtual method, how can you allow a derived class to override it but prevent any further overrides in subclasses?
AUse the new keyword in the derived class method
BMark the base class as sealed
CMark the base method as sealed virtual
DOverride the method in the derived class and mark it as sealed
Step-by-Step Solution
Solution:
  1. Step 1: Understand sealing overrides

    You can override a virtual method and seal it to prevent further overrides.
  2. Step 2: Apply sealed override in derived class

    Mark the overriding method as 'sealed override' in the derived class.
  3. Final Answer:

    Override the method in the derived class and mark it as sealed -> Option D
  4. Quick Check:

    Sealed override stops further subclass overrides [OK]
Quick Trick: Seal the override method to block further overrides [OK]
Common Mistakes:
MISTAKES
  • Sealing the base class instead of method
  • Trying to seal virtual methods directly
  • Using 'new' keyword instead of override

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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