Bird
0
0

Which of the following is the correct syntax to override a virtual method in a derived class?

easy📝 Syntax Q3 of 15
C Sharp (C#) - Polymorphism and Abstract Classes
Which of the following is the correct syntax to override a virtual method in a derived class?
Apublic override void MethodName() { }
Bpublic virtual void MethodName() { }
Cpublic new void MethodName() { }
Dpublic abstract void MethodName() { }
Step-by-Step Solution
Solution:
  1. Step 1: Understand override syntax

    To override a virtual method, the derived class method must use the override keyword.
  2. Step 2: Check options for correct usage

    public override void MethodName() { } uses override correctly; others use incorrect keywords or abstract without implementation.
  3. Final Answer:

    public override void MethodName() { } -> Option A
  4. Quick Check:

    Override method syntax = public override [OK]
Quick Trick: Override uses 'override' keyword in derived class [OK]
Common Mistakes:
MISTAKES
  • Using virtual instead of override in derived class
  • Using new keyword to override
  • Trying to override abstract method without override

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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