只问一个简单问题!!求解释。
class Circle{
double x,y,r;
final double PI=3.1415926;
double Perimeter,Area;
//构造方法初始化
public Circle(double x,double y,double r)
{
this.x=x;
this.y=y;
this.r=r;
}
//周长
public double getPerimeter()
{
this.Perimeter=2*PI*r;
return this.Perimeter;
}
//面积
public double getArea()
{
this.Area=PI*r*r;
return this.Area;
}
}
public class Cylinder extends Circle
{
int high;
double area;
double volume;
public Cylinder(int high)
{
super(2.0,3.0,50); //这一句如果不加,则显示找不到符号.是因为继承里面`子类与父类必须的构造方法?调用?这里有点含糊.望细解.
this.high=high;
}
//设置高.
public void setHigh(int high)
{
this.high=high;
}
//获取高.
protected int getHigh()
{
return this.high;
}
//计算表面积
public void getArea(Circle p1)
{
area=p1.getArea()*2+p1.r*2+high;
}
//计算体积
public void getVolume(Circle p1)
{
volume=p1.getArea()*high;
}
public static void main(String []args)
{
Cylinder px=new Cylinder(20);
Circle pxy=new Circle(1.0,2.0,3.0);
px.setHigh(15);
px.getArea(pxy);
System.out.println("表面积:"+px.area);
px.getVolume(pxy);
System.out.println("体积:"+px.volume);
}
}
/*
**/