package com.atguigu.exercise2;
public class Circle {
//属性
private double radius;//半径
//构造器
public Circle(){
radius = 1.0;
}
public Circle(double radius){
this.radius = radius;
}
//方法
public void setRadius(double radius){
this.radius = radius;
}
public double getRadius(){
return radius;
}
//返回圆的面积
public double findArea(){
return Math.PI*radius*radius;
}
}
package com.atguigu.exercise2;
public class Cylinder extends Circle{
//属性
private double length;//高
//构造器
public Cylinder(){
length = 1.0;
}
public Cylinder(double length){
this.length = length;
}
//方法
public double getLength(){
return length;
}
public void setLength(double length){
this.length = length;
}
public double findVolume(){
//return Math.PI*getRadius()*getRadius()*getLength();
return findArea()*getLength();
}
}
package com.atguigu.exercise2;
public class CylinderTest {
public static void main(String[] args) {
Cylinder cd = new Cylinder();
cd.setRadius(2);
cd.setLength(5);
cd.findVolume();
System.out.println("圆柱的体积是:" + cd.findVolume());
}
}