Circle
package 继承性练习2;
public class Circle {
private double radius;
public Circle() {
radius = 1;
}
public Circle(double radius) {
this.radius = radius;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public double findArea() {
return 3.14 * radius * radius;
}
}
Cylinder
package 继承性练习2;
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 Cylinder(double length) {
super();
this.length = length;
}
public double findVolume() {
return getLength() * findArea();
}
}
CylinderTest
package 继承性练习2;
public class CylinderTest {
public static void main(String[] args) {
Cylinder cylinder = new Cylinder(5);
cylinder.setRadius(2);
System.out.println("圆柱体积"+cylinder.findVolume());
}
}