Bird
0
0

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

easy📝 Syntax Q12 of 15
C Sharp (C#) - Interfaces
Which of the following is the correct syntax to declare a default interface method in C#?
Aabstract void Show() { Console.WriteLine("Hello"); }
Bvoid Show();
Cdefault void Show() { Console.WriteLine("Hello"); }
Dvoid Show() => Console.WriteLine("Hello");
Step-by-Step Solution
Solution:
  1. Step 1: Recall default method syntax in interfaces

    Default interface methods can have bodies using either block or expression-bodied syntax.
  2. Step 2: Identify correct syntax among options

    void Show() => Console.WriteLine("Hello"); uses expression-bodied syntax correctly inside interface method declaration.
  3. Final Answer:

    void Show() => Console.WriteLine("Hello"); -> Option D
  4. Quick Check:

    Default method syntax = method with body in interface [OK]
Quick Trick: Default methods have bodies, unlike abstract declarations [OK]
Common Mistakes:
MISTAKES
  • Using 'default' keyword before method
  • Omitting method body
  • Writing method body without braces or expression syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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