我沒有運氣從我的超類調用一個變量到我的子類。任何人都可以幫忙嗎?調用變量到超類的子類
//SUPERCLASS
public class Circle {
protected double radius;
protected double area;
//Some code to construct object and initialize radius
//Return Calculated Area
protected double getArea() {
area = Math.pow(radius, 2) * Math.PI;
return area;
}
}
//SUBCLASS
public class Cone extends Circle {
private double height;
//Some more code with constructors and different methods
public double getVolume() {
{
return (area * height/3)
}
}
有很多更多的代碼,但我在的主要問題是子類中的「區域」變量是0.00,我不知道該如何得到它等於「區域」所計算出的超
您應該在使用'area'之前運行'getArea()'。 – GAVD