定义一个Cube类,其中包含一个变量height,一个方法:计算立方体的体积(带形参,形参为面积)。并在其内部定义一个Rectangle类,其中包含两个变量width和height,一个方法:计算底面积。
5条回答 默认 最新
- ayuuuuuuuuuuuuuuuuuu 2016-05-21 01:55关注
class Cube { private double height; Cube() {} Cube(double height) { this.height = height; } public double volume(double area) { return area * height; } public class Rectangle { private double width; private double length; Rectangle(double width, double length) { this.width = width; this.length = length; } public double area() { return length * width; } } } public class Test { public static void main(String[] args) { Cube.Rectangle S = new Cube().new Rectangle(10.0, 10.0); double s = S.area(); Cube V = new Cube(20.0); double v= V.volume(s); System.out.println("立方体的体积 = " + v); } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 2无用