更新时间:2023-11-30 10:35:58
这是基于OP提供的内容的初步响应.
This is an initial response based on what little the OP provided.
您不会在派生类中覆盖获取器(并且基本的基本实现无法编译):
You are not overriding your getters in your deriving classes (and the basic implementation in the base can not compile) :
public abstract class Commodity {
public double getProductionCost() {
// no return value!
}
public double getRetailPrice() {
// no return value!
}
}
public abstract class TimsProduct extends Commodity{
private String name;
private double cost;
private double price;
public TimsProduct(String name, double cost, double price){
this.name = name;
this.cost = cost;
this.price = price;
}
public String getName(){
return name;
}
// no @Override!
public double getProductionCost(){
return cost;
}
// no @Override!
public double getRetailPrice(){
return price;
}
public String toString(){
return ("Name is: " + name + "cost is: " + cost + "price is: " + price );
}
}