Use inheritance to implement the following classes A Car tha

Use inheritance to implement the following classes: A Car that is a Vehicle and has a name, a max_speed value and an instance variable called the number of cylinders in its engine. Add public methods to set and get the values of these variables. When a car is printed (using the toString method), its name, max_speed and number_of_cylinders are shown. An Airplane that is also a vehicle and has a name, a max_speed value and an instance variable called the number_of_engines it has. Add public methods to set and get the values of these variables. When an airplane is printed (using the toString method), its name, max_speed and number_of_engines are shown. Write a VehicleDemo.java class that does the following: Creates an instance of a Car and an Airplane class. Assign values to the name, speed, number_of_cylinders (for the Car object and number_of_engines (for the Airplane object) variables. Compares which vehicle goes faster and prints the result. Prints the instances of the car and airplane classes.

Solution

class Vehicle { // member declarations } class Car extends Vehicle { // inherit accessible members from Vehicle // provide own member declarations } class Account { // member declarations } class SavingsAccount extends Account { // inherit accessible members from Account // provide own member declarations }
 Use inheritance to implement the following classes: A Car that is a Vehicle and has a name, a max_speed value and an instance variable called the number of cyl

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site