在下面的类Area中,定义主类Cube,它是Area的子类。 Class Cube有一个名为height的字段。 首先,创建一个Cube对象(具有3个正确的值),然后输出Cube的体积(volume = area * height)。
class Area {
private double length, width;
public Area (double a, double b){
length=a; width=b;
}
public double area(){
return length*width;
}
}
补充完整!
package pg1;
class Area {
private double length, width;
public Area (double a, double b){
length=a; width=b;}
public double area(){
return length*width;}
}
public class Cube {
double height;
public Cube(double height) {
this.height=height;
}
public static void main(String[] args) {
Cube h=new Cube(10);
Area hh=new Area(12, 10);
System.out.println(hh.area()*h.height);
}
}
运行结果:
1200.0