javA问题··请详细解释每一句的用法··谢谢了··

来源:百度知道 编辑:UC知道 时间:2024/06/02 09:43:38
class box{
double width;
double height;
double depth;

box(double w,double h, double d){
width=w;
height=h;
depth=d;
}
box(box ob) {
width=ob.width;
height=ob.height;
depth=ob.depth;

}
box(){
width=-1;
height=-1;
depth=-1;

}
box(double len){
width=height=depth=len;

}
double volume() {
return width*height*depth;

}
}

class bigbox{
public static void main (String[] args) {
box mybox1= new box(10,20,15);
box mybox2= new box();
box mybox3= new box(7);
box mycube= new box(mybox1);
double vol;
vol= mybox1.volume();
System.out.println("1."+vol);
vol= mybox2.volume();
System.out.println("2."+vol);
vol= mybox3.volume();
Syste

class box {

// 盒子的宽度
double width;

// 盒子的高度
double height;

// 深度
double depth;

// 类box的构造函数,带3个参数
box(double w, double h, double d) {
width = w;
height = h;
depth = d;
}

// 类box的构造函数,参数是box的实例ob
box(box ob) {
width = ob.width;
height = ob.height;
depth = ob.depth;

}

// 类box的构造函数,无参数
box() {
width = -1;
height = -1;
depth = -1;

}

// 一个参数的构造函数
box(double len) {
width = height = depth = len;

}

// 方法返回盒子的体积
double volume() {
return width * height * depth;

}
}

// 类bigbox
class bigbox {
public static void main(String[] args) {

// 初始化对象mybox1,调用box(double w, double h, double d)构造函数
box mybox1 = new box(10, 20, 15);

// 初始化对象mybox2,调用box()构造函数
box mybox2 =