Bird
0
0

You want to create a base class Vehicle with an abstract method StartEngine(). You also want to ensure every subclass implements StartEngine() differently. Which is the best approach?

hard🚀 Application Q15 of 15
C Sharp (C#) - Polymorphism and Abstract Classes
You want to create a base class Vehicle with an abstract method StartEngine(). You also want to ensure every subclass implements StartEngine() differently. Which is the best approach?
AMake Vehicle an abstract class with an abstract StartEngine() method.
BMake Vehicle a normal class and provide a default StartEngine() implementation.
CMake Vehicle an interface with StartEngine() method.
DMake Vehicle a sealed class with StartEngine() method.
Step-by-Step Solution
Solution:
  1. Step 1: Understand requirement for different implementations

    Each subclass must implement StartEngine() differently, so a base method without body is needed.
  2. Step 2: Choose correct class type and method declaration

    Abstract class Vehicle with abstract StartEngine() enforces subclasses to implement it uniquely.
  3. Final Answer:

    Make Vehicle an abstract class with an abstract StartEngine() method. -> Option A
  4. Quick Check:

    Abstract class + abstract method = enforced subclass implementation [OK]
Quick Trick: Use abstract class + abstract method for enforced overrides. [OK]
Common Mistakes:
MISTAKES
  • Using sealed class which prevents inheritance.
  • Using interface when base class behavior is needed.
  • Providing default method when unique implementations required.

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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