- 1
- 0
- 约4.72千字
- 约 31页
- 2018-03-14 发布于天津
- 举报
教学课件课件PPT医学培训课件教育资源教材讲义
(2)返回当前对象的引用 this可以作为函数的返回值,如下面的程序所示: // TestThisTwo.java public class TestThisTwo { int i = 0; TestThisTwo increment(){ i++; return this; } void printI(){ System.out.println(i = + i); } public static void main(String[] args) { new TestThisTwo().increment().increment().increment().printI(); } } (3)在构造方法中调用构造方法 既然构造方法可以重载,那么使用一个构造方法创建对象时可以借助另外一个构造方法,这是必须借助this,示例代码如下: // TestThisThree.java public class TestThisThree { int i = 0,j = 0; TestThisThree(int i){ this.i = i; } TestThisThree(int i,int j){ this(i); this.j = j; } 第5讲 初识面向对象 第5讲 初识面向对象
原创力文档

文档评论(0)