Bird
0
0

What is wrong with this interface implementation?

medium📝 Debug Q7 of 15
C Sharp (C#) - Interfaces
What is wrong with this interface implementation?
interface IWorker {
    void Work();
}
class Employee : IWorker {
    public void Work(int hours) { Console.WriteLine($"Working {hours} hours"); }
}
ANo error, code is valid.
BInterface methods cannot have parameters.
CEmployee class must be abstract.
DEmployee does not implement the interface method signature correctly.
Step-by-Step Solution
Solution:
  1. Step 1: Compare method signatures

    IWorker defines Work() with no parameters; Employee defines Work(int hours).
  2. Step 2: Check interface implementation rules

    Method signatures must match exactly to implement an interface method.
  3. Final Answer:

    Employee does not implement the interface method signature correctly. -> Option D
  4. Quick Check:

    Interface method signatures must match exactly [OK]
Quick Trick: Method signatures must match exactly to implement interface [OK]
Common Mistakes:
MISTAKES
  • Adding parameters to interface method implementation
  • Thinking interface methods cannot have parameters
  • Assuming partial implementation is allowed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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