Bird
0
0

Find the error in this code snippet:

medium📝 Debug Q6 of 15
C Sharp (C#) - Interfaces

Find the error in this code snippet:

interface IPrinter {
  void Print();
}
class Document : IPrinter {
  public void Print(string text) {
    Console.WriteLine(text);
  }
}
AMissing class inheritance
BInterface cannot have methods
CMethod signature mismatch in Document class
DPrint method should be private
Step-by-Step Solution
Solution:
  1. Step 1: Compare interface and class method signatures

    Interface declares Print() with no parameters; Document class defines Print(string text) with a parameter.
  2. Step 2: Identify mismatch error

    Because signatures differ, Document does not correctly implement the interface method, causing a compile error.
  3. Final Answer:

    Method signature mismatch in Document class -> Option C
  4. Quick Check:

    Interface method signatures must match exactly [OK]
Quick Trick: Method signatures must match interface exactly [OK]
Common Mistakes:
MISTAKES
  • Adding parameters to interface methods
  • Ignoring interface method requirements
  • Wrong access modifiers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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