Bird
0
0

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

easy📝 Syntax Q12 of 15
C Sharp (C#) - Polymorphism and Abstract Classes
Which of the following is the correct syntax to declare a virtual method in a C# class?
Avirtual public void Display() { }
Bpublic void virtual Display() { }
Cpublic virtual void Display() { }
Dpublic override void Display() { }
Step-by-Step Solution
Solution:
  1. Step 1: Recall virtual method syntax

    The keyword virtual comes after the access modifier and before the return type and method name.
  2. Step 2: Check each option

    public virtual void Display() { } matches correct syntax: public virtual void Display() { }. Options B and C have wrong order, D uses override which is for overriding, not declaring virtual.
  3. Final Answer:

    public virtual void Display() { } -> Option C
  4. Quick Check:

    virtual keyword after access modifier [OK]
Quick Trick: virtual keyword goes right after access modifier [OK]
Common Mistakes:
MISTAKES
  • Placing virtual after method name
  • Using override instead of virtual to declare
  • Wrong keyword order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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