Question: Using Java and what you know about inheritance: 1. Use proper encapsulation to write the following classes a. Create a Vehicle class that has two

Using Java and what you know about inheritance:

Using Java and what you know about inheritance: 1. Use proper encapsulation

1. Use proper encapsulation to write the following classes a. Create a Vehicle class that has two instance variables: doors and mileage. Doors is an int and mileage is a double. payload instance variable that is an integer engine size variable that is a double b. Create a Truck class that inherits from Vehicle. A Truck class should have a c. Create a Pickup class that inherits from Truck. A Pickup class should have an d. Create a Trailer class that inherits from Truck. A Trailer class should have a String variable called name. 2. In each of the above classes, you must override the Object class toStringmethod that returns a String value. You should return a String that accurately represents the current Object. You should not duplicate code in these methods. 3. In a separate Driver class, you must do the following: Create a main method to test your classes. Create at least 1 Vehicle, Truck, Pickup and Trailer object. Make various calls to all of the methods to make sure your classes are implemented correctly. Be sure to print out each object utilizing the toString method

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!