QuestionQ192
Working with InheritanceGiven these requirements:
- Bus and Boat are Vehicle-type classes.
- The
start()andstop()methods perform common operations across the Vehicle class type. - The
ride()method performs a unique operation for each type of Vehicle.
Which set of actions satisfies the requirements with optimized code?
- A
- Create an abstract class Vehicle by defining start() and stop() methods, and declaring the ride() abstract method. 2. Create Bus and Boat classes by inheriting the Vehicle class and overriding the ride() method.
- B
- Create an interface Vehicle by defining start() and stop() methods, and declaring the ride() abstract method. 2. Create Bus and Boat classes by implementing the Vehicle class.
- C
- Create an abstract class Vehicle by declaring stop(), start(), and ride() abstract methods. 2. Create Bus and Boat classes by inheriting the Vehicle class and overriding all the methods.
- D
- Create an interface Vehicle by defining default stop(), start(), and ride() methods. 2. Create Bus and Boat classes by implementing the Vehicle interface and overriding the ride() method.
Community Discussion