Java:this示例

 1 public class Leaf {
 2 
 3     int i = 0;
 4 
 5     Leaf inceament() {
 6         i++;
 7         return this;
 8     }
 9 
10     void print() {
11         System.out.println("i= " + i);
12     }
13 
14     
15     public static void main(String[] args) {
16         Leaf x = new Leaf();
17         x.inceament().inceament().inceament().print();
18     }
19 }

输出

i= 3

有几个inceament就输出几

 

posted @ 2015-04-19 00:33  陶修瑕  阅读(134)  评论(0编辑  收藏  举报