码迷,mamicode.com
首页 > 编程语言 > 详细

Java:this示例

时间:2015-04-19 01:11:18      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:

 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就输出几

 

Java:this示例

标签:

原文地址:http://www.cnblogs.com/taoxiuxia/p/4438478.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!