Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java Program The Vehicle class and its subclasses ( filename: TestVehicle.java) Define a class named Vehicle that contains the manufacturers name, and the number of
Java Program
The Vehicle class and its subclasses (filename: TestVehicle.java)
- Define a class named Vehicle that contains the manufacturers name, and the number of wheels, and appropriate constructors and accessor and mutator methods. Also override the toString() method that returns an English sentence describing the manufacturer's name and the number of wheels.
- Next define a class named Truck that extends the Vehicle class. The Truck class has two additional data fields. They are the load capacity in tons (type double) and towing capacity in pounds (type int). Include appropriate constructor(s) and accessors and mutators. This class should override the toString() method to return a string that includes all the information about a Truck object.
- Define a class named Car that also extends the Vehicle class. This class has an additional data field: the number of passengers. Include appropriate constructor(s) and accessors and mutators. Finally override the toString() method to return a string that includes all the information about a Car object.
- Directly inside the public class TestVehicle, define a method with the following header:
public static void displayObject(Vehicle object)
This method calls the toString() method of the Vehicle object to display the vehicle information.
- Create the main method that creates one Vehicle object, one Truck object, and one Car object. Then call thedisplayObject method three times to pass the three objects above, respectively, to display the vehicle information for each vehicle.
- The overall structure of the program file TestVehicle.java should be like the following:
public class TestVehicle
{
public static void main(String[] args)
{
}
public static void displayObject(Vehicle object)
{
}
}
class Vehicle
{
}
class Truck extends Vehicle
{
}
class Car extends Vehicle
{
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started