谁帮我做一下java题目好吗

来源:百度知道 编辑:UC知道 时间:2024/05/10 10:19:53
定义一个盒子的类Box,有宽,高,深等属性,定义构造函数对盒子的属性进行初始化,并定义一个方法ShowBox()用于显示盒子的属性,并创建Box类的对象,并将此对象的信息显示在屏幕上

public class Box{
private int width = 0;
private int height = 0;
private int deep = 0;

public Box(int newWidth,int newHeight,int newDeep){
width = newWidth;
height = newHeight;
deep = newDeep;
}

public String ShowBox(){
System.out.println("width = " + width);
System.out.println("heigth = " + height);
System.out.println("deep = " + deep);
}

public static void main(Stirng s){
Box b = new Box(10,20,30);
b.ShowBox();
}
}