继承性 练习 圆柱
package com.atgui.exer1;
public class Circle
{
private double radius;
public Circle() {
radius = 1.0;
}
public void setRadius(double radius) {
this.radius = radius;
}
public double getRadius() {
return this.radius;
}
public double findArea() {
return Math.PI*this.radius*this.radius;
}
}
package com.atgui.exer1;
public class Cylinder extends Circle
{
private double length;
public Cylinder() {
length = 1;
}
public void setLength(double lenght) {
this.length = lenght;
}
public double getLength() {
return this.length;
}
public double findVolume() {
return findArea() * getLength();
}
}
package com.atgui.exer1;
public class CylinderTest
{
public static void main(String[] args)
{
Cylinder cy = new Cylinder();
cy.setRadius(2.1);
cy.setLength(3.4);
double volume = cy.findVolume();
System.out.println("圆柱的体积为" + volume);
double area = cy.findArea();
System.out.println("圆柱底面的面积为" + area);
}
}