java super 求高人看看这个程序子类的写法那里错了,子类要求输出圆柱的体积,但结果总是0。求高人指点!

[复制链接]
查看11 | 回复3 | 2011-11-3 15:34:17 | 显示全部楼层 |阅读模式
你的圆柱体底面半径为0 所以体积也是0 了class Cylinder extends Circle{private double hight;
Cylinder(double r, double h){//这里传入底面半径
super(r);//调用父类构造方法
hight=h;
}
double getVol(){
double area;
area=super.getArea();
return area*hight;
}
void dispVol(){
System.out.print("圆柱的体积:"...
回复

使用道具 举报

千问 | 2011-11-3 15:34:17 | 显示全部楼层
正常阿Cylinder b = new Cylinder(h);这里没有求设置地面积,所以super.area()恒为0 修改地方1class Cylinder extends Circle {private double hight;public Cylinder(double h, double r) {s...
回复

使用道具 举报

千问 | 2011-11-3 15:34:17 | 显示全部楼层
因为你是给Circle a=new Circle(r);这个a赋值的半径Cylinder b=new Cylinder(h);b继承自父类的 Circle(){banjing=0;}半径还是0所以打印出来的体积是0你打印b 的 面积 和周长都是0 你试试...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行