Question: JAVA PROGRAMMING Create and implement a class hierarchy where Vehicle superclass and 'Motorcycle' and 'Truck' are the subclasses. Common to both Motorcycle and Truck are

JAVA PROGRAMMING

Create and implement a class hierarchy where Vehicle superclass and 'Motorcycle' and 'Truck' are the subclasses.

Common to both Motorcycle and Truck are the variables wheels and weight and the method display( ). The attributes should not be accessible outside the class. display( ) will printout the wheels and weight and should only be accessible to the common class and all subclasses.

Data unique to the Motorcycle class should be passengers. Data unique to the Truck class should be payload. Include methods to display this information.

Draw the class hierarchy.

Create a 'driver' class to test your hierarchy. Allow for the creation of multiple objects by the user by storing the references in an array of Vehicle. You should allow the user to create a motorcycle object by entering 'm', and then ask for relevant attributes. Along the same lines, use 't' to create the truck object.

After inputting all data, print out the contents of each object by calling the display( ) method. Print the number of passengers in case of a motorcycle or the payload in case of a truck. Note that the display( ) method will have to be overridden for the different subclasses

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!