这是源代码
class Circle {
double x;
double y;
double r;
Circle(double x,double y,double r)
{
this.x=x;
this.y=y;
this.r=r;
}
public void setX(double x)
{
this.x=x;
}
public void setY(double y)
{
this.y=y;
}
public void setR (double r)
{
this.r=r;
}
public double getX()
{
return x;
}
public double getY()
{
return y;
}
public double getR ()
{
return r;
}
public double area()
{
return rr3.1416;
}
public double perimeter()
{
return 2r3.1416;
}
public void show()
{
System.out.print("x="+x+", y="+y+", Radius="+r);
}
}
class Cylinder extends Circle {
double h;
Cylinder(double x,double y,double r,double h)
{
super(x,y,r);
this.h=h;
}
public void setH (double h)
{
this.h=h;
}
public double getH ()
{
return h;
}
public double area() //计算圆柱体的表面积,覆盖了父类的area()函数
{
return perimeter()*h+super.area()*2;
}
public double volume() //计算圆柱体的体积
{
return super.area()*h;
}
public static void main(String[] args)
{
Cylinder cylinder=new Cylinder(1,1,4,8);
cylinder.show();
System.out.println(", Height="+cylinder.getH ());
System.out.println("Area="+cylinder.area());
System.out.println("Volume="+cylinder.volume());
}
}