Bird
0
0

Which of the following is the correct syntax to declare an interface in C#?

easy📝 Syntax Q3 of 15
C Sharp (C#) - Interfaces
Which of the following is the correct syntax to declare an interface in C#?
Aabstract interface IExample { void DoWork(); }
Binterface IExample { void DoWork(); }
Cclass IExample { abstract void DoWork(); }
Dinterface IExample { void DoWork() {} }
Step-by-Step Solution
Solution:
  1. Step 1: Recall interface syntax

    Interfaces use the keyword 'interface' without 'abstract' and declare method signatures without bodies.
  2. Step 2: Check each option

    interface IExample { void DoWork(); } correctly declares an interface with a method signature only.
  3. Final Answer:

    interface IExample { void DoWork(); } -> Option B
  4. Quick Check:

    Interface syntax = 'interface' + method signatures [OK]
Quick Trick: Interface methods have no body, no 'abstract' keyword needed [OK]
Common Mistakes:
MISTAKES
  • Adding 'abstract' keyword to interface
  • Providing method bodies in interface methods
  • Declaring interface as a class

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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