【发布时间】:2020-10-29 01:43:25
【问题描述】:
对于分配,我应该有一个构造函数,它以姓名、地址、电话、品牌、型号、容量和 numAxles 作为参数。前五个应该传递给超类 Vehicle。 UML 说我的超类应该将对象“person”作为第一个参数(它来自另一个类,并带有姓名、地址和电话)。如何将名称、地址和电话作为参数从 Truck 构造函数传递给超类?
这是UML
卡车类
public Truck(Person person, String make, String model, int year, int mileage, int capacity, int numAxles){
super(person, make, model, year, mileage);
}
public Truck(String name, String address, String phone, String make, String model, int capacity, int numAxles ){
super(name, address, phone, make, model);
}
Vehicle 超类
public Vehicle(Person person, String make, String model, int year){
setMileage(0);
}
【问题讨论】:
-
你的课程真的扩展了
Vehicle吗? -
是的,类标题是:public class Truck extends Vehicle{