Vehicle.java
// Superclass or base class for Automobile and Truck (not shown)
public class Vehicle
{
private String
make;
private String vin;
public Vehicle(String
make0, String vin0)
{
make = make0;
vin = vin0;
}
public String
getMake() { return make; }
public String getVIN() {
return vin; }
}
Automobile.java
public class Automobile extends Vehicle
{
private String model;
private int year;
public Automobile(String make0, String model0, int year0, String vin0)
{
super(make0, vin0);
model = model0;
year = year0;
}
public String getModel() { return model; } // even more compact way
public int getYear() { return year; }
}
1. Create a Vehicle object named mover of make Toyota and VIN “1B234”.
2.
Create an Automobile object named car1 of make
Mercedes, model E350, VIN “1G456”, and year 2012.
3.
Give the car1 object another reference, this one
of type Vehicle, named shaker.
4.
Create an array of 2 Vehicles named goodCars
containing the Vehicle objects named mover and shaker.
5. Write a loop to print out the makes of the Vehicles in goodCars.