Bird
Raised Fist0

Which of the following is the correct syntax to declare a sealed method in C#?

easy📝 Syntax Q12 of Q15
C Sharp (C#) - Inheritance
Which of the following is the correct syntax to declare a sealed method in C#?
Asealed public void MyMethod() { }
Bpublic override sealed void MyMethod() { }
Cpublic sealed void MyMethod() { }
Doverride sealed public void MyMethod() { }
Step-by-Step Solution
Solution:
  1. Step 1: Recall sealed method syntax

    A method can only be sealed if it overrides a base method, so it must have override sealed modifiers.
  2. Step 2: Check options for correct order and modifiers

    public override sealed void MyMethod() { } correctly uses public override sealed void MyMethod(). Other options miss override or have wrong order.
  3. Final Answer:

    public override sealed void MyMethod() { } -> Option B
  4. Quick Check:

    Sealed method = override + sealed [OK]
Quick Trick: Sealed methods must override and use 'override sealed' [OK]
Common Mistakes:
MISTAKES
  • Declaring sealed method without override
  • Wrong order of modifiers
  • Missing override keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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