2020.8.26第五十一天

例 9.4对象数组

 1 public class cjava {
 2     public static void main(String[] args) {
 3        Box a[]= {new Box(10,12,15),new Box(15,18,20),new Box(16,20,26)};
 4        System.out.println("The volume of a[0] is "+a[0].volume());
 5        System.out.println("The volume of a[1] is "+a[1].volume());
 6        System.out.println("The volume of a[2] is "+a[2].volume());
 7 }
 8 }
 9 class Box{
10     int height;
11     int width;
12     int length;
13     Box(int h,int w,int len){
14         height=h;
15         width=w;
16         length=len;
17     }
18     int volume() {
19        return (height*width*length);
20     }
21 }

 

 2.遇到的问题:无

3.明天继续写例题

posted @ 2020-08-26 19:44  敲敲代代码码  阅读(93)  评论(0编辑  收藏  举报