}
Exercise:
Design a Transportation class:
1. Super class included all class instances (CarModel, CarType,
CarName…etc)
2. Subclass calls the superclass and overridden methods of
superclass. (the methods in superclass as you like).
3. Don’t re-define the class instance in the subclass.
4. Modify the overridden method in the subclass.
public class Transportation extends Car {
public Transportation(String carModel, String carType, String carName) {
super(carModel, carType, carName);
}
@Override
public String toString() {
return "Transportation: " + super.toString();
}
}
public class Car {
private String carModel;
private String carType;
private String carName;
public Car(String carModel, String carType, String carName) {
this.carModel = carModel;
this.carType = carType;
this.carName = carName;
}
@Override
public String toString() {
return carModel + " " + carType + " " + carName;
}
}
Comments
Leave a comment