Bird
0
0

Find the error in this code snippet:

medium📝 Debug Q7 of 15
C Sharp (C#) - Interfaces
Find the error in this code snippet:
interface IPrinter { void Print(); }
class Document : IPrinter { void Print() { Console.WriteLine("Printing"); } }
APrint method must be public
BInterface cannot have void methods
CClass must be abstract
DConsole.WriteLine is invalid here
Step-by-Step Solution
Solution:
  1. Step 1: Check method accessibility

    Interface methods are public by default; implementation must be public.
  2. Step 2: Identify missing access modifier

    Print method in Document is missing 'public', so it is private by default, causing error.
  3. Final Answer:

    Print method must be public -> Option A
  4. Quick Check:

    Interface methods require public implementation [OK]
Quick Trick: Implement interface methods as public in classes [OK]
Common Mistakes:
MISTAKES
  • Omitting public keyword on interface methods
  • Thinking interface methods can be private
  • Assuming class must be abstract

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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