Bird
0
0

Which of the following is the correct way to declare a class Car that implements interface IVehicle?

easy📝 Syntax Q3 of 15
C Sharp (C#) - Interfaces
Which of the following is the correct way to declare a class Car that implements interface IVehicle?
Aclass Car implements IVehicle {}
Bclass Car : IVehicle {}
Cclass Car inherits IVehicle {}
Dinterface Car : IVehicle {}
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct syntax for class implementing interface

    In C#, use ':' to implement interfaces in class declaration.
  2. Step 2: Check each option

    class Car : IVehicle {} uses correct syntax 'class Car : IVehicle {}'. Others use invalid keywords or declare interface instead of class.
  3. Final Answer:

    class Car : IVehicle {} -> Option B
  4. Quick Check:

    Class implementing interface syntax = ':' [OK]
Quick Trick: Use ':' after class name to implement interfaces [OK]
Common Mistakes:
MISTAKES
  • Using 'implements' keyword like Java
  • Using 'inherits' keyword incorrectly
  • Declaring interface instead of class

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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