class Cuboid { double a; double b; double h; double area; public Cuboid(double a, double b,double h){ this.a = a; this.b = b; this.h = h; } public Cuboid() { // TODO Auto-generated constructor stub } double Area(){ area=a*b*h; return area; } } public class Test67{ public static void main(String args[]){ Cuboid cuboid = new Cuboid(); double a=12.5,b=5.2,h=2.5; Cuboid.Cuboid(a,b,h); System.out.println("长方提体的体积是:"+cuboid.Area());}}这是题目:1. 编程扩展下面的矩形类(Rect)为长方体类(Cuboid),要求增加高度(h)属性,并求出长方体的体积(Volume)。public class Rect {double a;double b; public Rect(double a, double b){this.a = a;this.b = b;}public double Area(){return a * b;}}
1 回答
已采纳
Its_forever
TA贡献361条经验 获得超328个赞
public class Rect { double a; double b; double c; //带三个参数(长宽高)的构造函数 public Rect(double a, double b,double c){ this.a = a; this.b = b; this.c = c; } public double Area(){ return a * b* c; } public static void main(String[] args) { Rect r = new Rect(2.1,3.2,4.3); System.out.println(r.Area()); } }
添加回答
举报
0/150
提交
取消