Java学习的第五十二天

1.例9.4对象数组的使用方法

public class Cjava {
public static void main(String[]args) {
Box b[] = {new Box(10,12,15),new Box(15,18,20),new Box(16,20,26)};
System.out.println("The volume of b[0]="+b[0].volume());
System.out.println("The volume of b[1]="+b[1].volume());
System.out.println("The volume of b[2]="+b[2].volume());
    }
}
class Box{
    int h,w,l;
    Box(int x,int y,int z){
        h=x;w=y;l=z;
    }
    int volume(){
        return (h*w*l);
    }
}

 2.没问题

3.继续写例题

原文地址:https://www.cnblogs.com/feng747/p/13574068.html