2020.8.27第五十二天

例9.5对象的赋值

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

 

 2.遇到的问题:无

3.明天继续写例题

 

posted @ 2020-08-27 20:43  敲敲代代码码  阅读(122)  评论(0编辑  收藏  举报