Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q14 of 15
C Sharp (C#) - Interfaces
Identify the error in this code snippet:
interface IVehicle { void Drive(); }
class Car : IVehicle { }
ACar class should be abstract
BInterface IVehicle cannot be empty
CDrive() method should have a body in interface
DCar class must implement Drive() method
Step-by-Step Solution
Solution:
  1. Step 1: Check interface implementation rules

    A class implementing an interface must provide bodies for all interface methods.
  2. Step 2: Analyze given code

    Car class implements IVehicle but does not define Drive(), causing a compile error.
  3. Final Answer:

    Car class must implement Drive() method -> Option D
  4. Quick Check:

    Implement all interface methods [OK]
Quick Trick: Implement all interface methods in the class [OK]
Common Mistakes:
MISTAKES
  • Thinking interface methods have bodies
  • Assuming empty class is valid implementation
  • Confusing abstract class requirement

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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