匿名用户
1级
2011-11-27 回答
//创建圆的类
public class round {
protected double radius;
protected double area;
public void setRadius(double radius) { //设置圆的半径
this.radius = radius;
}
public double getArea() { //求圆的面积
return 3.14*radius*radius;
}
}
//创建继承自圆的圆柱体类
public class cylindrical extends round{
private double height;
private double voluem;
public void setHeight(double height){ //设置圆柱体的高
this.height = height;
}
public double getVoluem() { //求圆柱体的体积,半径继承自圆的类,不用重复定义
return 3.14*radius*radius*height;
}
}
//主函数类(测试类):
public class testMain {
public static void main(String[] args){
round round1 = new round();
cylindrical cylindrical1 = new