Question: you will find the Vehicle interface and code for two classes, Bicycle and Motorcycle. Rewrite these classes using inheritance to eliminate duplicated code as

you will find the Vehicle interface and code for two classes, Bicycle

 

you will find the Vehicle interface and code for two classes, Bicycle and Motorcycle. Rewrite these classes using inheritance to eliminate duplicated code as much as possible. Specifically, you must: (a) Create an abstract class AbstractVehicle containing, as much as possible, the features that are common to both types of vehicle. (b) Then, rewrite the Bicycle and Motorcycle classes to extend the base class Abstract Vehicle and reuse the common code. Your rewritten Bicycle and Motorcycle classes should have exactly the same public API as the originals. All instance variables must be private (no protected!). You may add additional protected or private methods as you wish. Your Abstract Vehicle must have a protected constructor.

Step by Step Solution

3.45 Rating (155 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

heres how you can rewrite the Bicycle and Motorcycle classes using inheritance to eliminate duplicated code by creating an abstract class AbstractVehi... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!