![](https://i-blog.csdnimg.cn/blog_migrate/8518d1e49d2656b4638c332ec7324d89.png)
Circle类
public class Circle {
private double radius;
public Circle(){
radius = 1.0;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public double findArea(){
double area = Math.PI * radius * radius;
return area;
}
}
Cylinder 类
public class Cylinder extends Circle{
private double length;
public Cylinder() {
length = 1.0;
}
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
public double findVolume(){
return findArea() * length;
}
}
CylinderTest测试类
public class CylinderTest {
public static void main(String[] args) {
Cylinder cylinder = new Cylinder();
cylinder.setRadius(10);
cylinder.setLength(10);
System.out.println("圆柱的体积: " + cylinder.findVolume());
System.out.println("底面圆的面积:" + cylinder.findArea());
}
}