Bird
0
0

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

easy📝 Syntax Q12 of 15
C Sharp (C#) - Interfaces

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

?
Ainterface IAnimal { void Speak(); }
Bclass IAnimal { void Speak(); }
Cinterface IAnimal() { void Speak(); }
Dinterface IAnimal { void Speak() {} }
Step-by-Step Solution
Solution:
  1. Step 1: Check interface declaration syntax

    Interfaces use the keyword 'interface' followed by the name and method signatures without bodies.
  2. Step 2: Identify correct method signature

    Method declarations in interfaces do not have bodies, so no curly braces after method.
  3. Final Answer:

    interface IAnimal { void Speak(); } -> Option A
  4. Quick Check:

    Interface syntax = keyword + method signatures [OK]
Quick Trick: Interfaces have method signatures only, no bodies [OK]
Common Mistakes:
MISTAKES
  • Adding parentheses after interface name
  • Using class keyword instead of interface
  • Providing method bodies inside interface

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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