我想要獲得一個子類方法來從超類返回變量,但返回值不斷給我空回報。我的猜測是,我錯過了對超類的某種引用。它是從子類方法returnweight()返回值0(零)的值權重。Java子類的方法返回零值
abstract class Vehicle{
protected float weight;
public Vehicle(float weight){
}
public abstract float returnweight();
}
class Bike extends Vehicle{
public Bike(float weight){
super(weight);
}
public float returnweight(){
return weight;//This returns as zero no matter what
}
}
代碼冷凝和翻譯(沒有編譯器檢查在這個崗位語法)提前 謝謝!
我的壞!錯過了翻譯。 Fordon =車輛。糾正原代碼 – Tobias 2010-01-29 21:43:25
是的,就是這樣!這樣的初學者錯誤。由於超類是抽象的,我只是覺得我會把所有東西都留在空中。非常感謝你的幫助! – Tobias 2010-01-29 21:52:27