我想要获得一个子类方法来从超类返回变量,但返回值不断给我空回报。我的猜测是,我错过了对超类的某种引用。它是从子类方法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