public class Fjava {
public static void main(String[] args)
{
Cylinder c=new Cylinder(2,3);
c.show();
c.showVolume();
}
public static void main(String[] args)
{
Cylinder c=new Cylinder(2,3);
c.show();
c.showVolume();
}
}
public class Circle {
private double Radius;
public Circle()
{
this.Radius=0;
}
Circle(double r)
{
this.Radius=r;
}
double getArea()
{
return 2*Math.PI*Radius;
}
double getPerimeter()
{
return Math.PI*Radius*Radius;
}
void show()
{
System.out.println("半径为"+Radius+" 周长为"+getPerimeter()+" 面积为"+getArea());
}
}
public class Cylinder extends Circle{
private double high;
public Cylinder(double r,double h)
{
super(r);
this.high=h;
}
double getVolume()
{
return getArea()*high;
}
void showVolume()
{
System.out.println("圆柱体的体积为:"+getVolume());
}
}