题目描述
代码
package extendstest;
public class Circle {
private double radius;
public Circle() {
radius=1.0;
}
public double getRadlus() {
return radius;
}
public void setRadlus(double radlus) {
this.radius = radlus;
}
//返回面积
public double findArea() {
return Math.PI*radius*radius;
}
}
public class Cylinder extends Circle{
private double length;
public Cylinder(){
length=1.0;
}
public void setLength(double length) {
this.length=length;
}
public double getLength() {
return length;
}
public double findVolume() {
//return Math.PI*getRadlus()*getRadlus()*getLength();
return findArea()*getLength() ;
}
}
public class CylinderTest {
public static void main(String[] args) {
Cylinder cy = new Cylinder();
cy.setRadlus(2.1);
cy.setLength(3.4);
System.out.println("圆柱的体积为"+cy.findVolume());
}
}
结果