1、创建circle类
package test2;
/**
* 〈一句话功能简述〉<br>
* 〈圆〉
*
* @author abu
* @create 2019/7/13
* @since 1.0.0
*/
public class Circle {
double radius;
public Circle(){
radius = 1;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public double findArea(){
return Math.PI * radius * radius;
}
}
2、创建cylinder类
package test2;
/**
* 〈一句话功能简述〉<br>
* 〈圆柱〉
*
* @author abu
* @create 2019/7/13
* @since 1.0.0
*/
public class Cylinder extends Circle {
private double length;
public Cylinder(){
length = 1;
}
public double getLength(){
return length;
}
public void setLength(double length){
this.length = length;
}
public double findVolume(){
//return Math.PI * this.getRadius() * this.getRadius() * length;
return findArea() * length;
}
}
3、创建测试类
package test2;
/**
* 〈一句话功能简述〉<br>
* 〈圆柱测试〉
*
* @author abu
* @create 2019/7/13
* @since 1.0.0
*/
public class TestCylinder {
public static void main(String[] args){
Cylinder c = new Cylinder();
double area = c.findVolume();
System.out.println(area);
c.setRadius(2);
c.setLength(3);
area = c.findVolume();
System.out.println(area);
}
}