Java SE 8 Programmer I — Question 149

Given these requirements:
✑ Bus and Boat are Vehicle type classes.
✑ The start() and stop() methods perform common operations across the Vehicle class type.
✑ The ride() method performs a unique operations for each type of Vehicle.
Which set of actions meets the requirements with optimized code?

Answer options

Correct answer: A

Explanation

The correct answer is A because it effectively utilizes an abstract class to define common methods (start() and stop()) while allowing the ride() method to be uniquely implemented in the Bus and Boat classes. Option B incorrectly uses an interface, which does not allow for the definition of non-abstract methods. Option C is incorrect because it declares all methods as abstract, which is unnecessary for the common operations. Option D misuses an interface by declaring default methods, which is not aligned with the requirement for abstract functionality.