读书人

The key word quot;thisquot; in java

发布时间: 2012-11-05 09:35:12 作者: rapoo

The key word "this" in java.
今天早上突然想起来java中有个key word叫this,以前都没怎么注意,于是写下帮助记忆。

package org.iteye.bbjava.thistest;public class UseThisTest {private ThisTest tt = new ThisTest();public void test(){System.out.println("Do nothing!");}public void callTest(){ThisTest utt1 = new ThisTest(this);//把当前对象作为参数传传递。this.tt.test();System.out.println("The key word 'this' in  the UseThisTest class:"+this);}public static void main(String []args0){UseThisTest utt = new UseThisTest();utt.test();utt.callTest();}}


output:引用Do nothing!
Hello!my name is org.iteye.bbjava.thistest.UseThisTest@c17164
The key word 'this'!
The key word this in ThisTest:org.iteye.bbjava.thistest.ThisTest@1fb8ee3
The key word 'this' in the UseThisTest class:org.iteye.bbjava.thistest.UseThisTest@c17164

读书人网 >编程

热点推荐