(2)java程序设计基础 能运行马上采纳,谢谢了哦?

来源:百度知道 编辑:UC知道 时间:2024/05/24 07:55:38
(2) 继承上题中的圆Circle类,派生圆柱体类Cylinder,要求如下:
 Cylinder类的成员变量:
height 表示圆柱体的高
 Cylinder类的方法成员:
Cylinder(double r,double h) 构造方法,创建Cylinder对象时将圆半径初始化为r,圆柱高初始化为h
double getHeight() 获得圆柱体的高
double getVol() 获得圆柱体的体积
void dispVol() 将圆柱体的体积输出到屏幕

//圆柱类
public class Cylinder extends Circle {
/**
* @param args
*/
Circle c= new Circle();

private Double height;//height 表示圆柱体的高 //Cylinder类的成员变量:
//Cylinder类的方法成员:
public Cylinder(double r,double h){// 构造方法,
this.height=h;//圆柱高初始化为h
c.setRadius;//创建Cylinder对象时将圆半径初始化为r
}
/**
* 获得圆柱体的体积
* @return double
*/
public double getVol(){
return c.gerArea()*height;

}
/**
* 将圆柱体的体积输出到屏幕
*/
public void dispVol(){
System.out.println("体积:"+this.getVol());
}
/**
* 测试main方法
* @param args
*/

public static void main(String[] args) {
// TODO Auto-generated method stub
Cylinder cy=new Cylinder(2.2,2.6);
cy.dispVol();

}

public Double getHeight() {//获得圆柱体的高
return height;
}

public void setHe