黑色星球
风遇浪,海市蜃楼

this

 1 public class Apple
 2 {
 3     public String name;
 4     public String color;
 5     public double weight;
 6     public Apple(){}
 7     // 两个参数的构造器
 8     public Apple(String name , String color)
 9     {
10         this.name = name;
11         this.color = color;
12     }
13     // 三个参数的构造器
14     public Apple(String name , String color , double weight)
15     {
16         // 通过this调用另一个重载的构造器的初始化代码
17         this(name , color);
18         // 下面this引用该构造器正在初始化的Java对象
19         this.weight = weight;
20     }
21 }

 

简写

posted on 2017-03-19 16:06  黑色星球  阅读(147)  评论(0编辑  收藏  举报