`
BBjava
  • 浏览: 119689 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

The key word "this" in java.

阅读更多
今天早上突然想起来java中有个key word叫this,以前都没怎么注意,于是写下帮助记忆。
package org.iteye.bbjava.thistest;

public class ThisTest {
	private String thisStr="The key word 'this'!";
	public ThisTest(){
		
	}
	
	//this引用构造方法
	public ThisTest(String thisStr){
		this();
		this.thisStr=thisStr;//特别指出,当前使用的是实列变量,而不是静态变量或局部变量。
	}
	public ThisTest(UseThisTest utt){
		System.out.println("Hello!my name is "+utt);
	}
	
	//
	public void test(){
		System.out.println(this.thisStr);
		System.out.println("The key word 'this' in the ThisTest class:  "+this);
	}
	
	//返回当前实列
	public ThisTest returnMyself(){
		return this;
	}
	
	
	public static void main(String []args){
		ThisTest tt=new ThisTest();
		tt.test();
		System.out.println("returnMyself:"+tt.returnMyself());
	}
}


output
引用
The key word 'this'!
The key word 'this' in the ThisTest class:  org.iteye.bbjava.thistest.ThisTest@de6ced
returnMyself:org.iteye.bbjava.thistest.ThisTest@de6ced


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
分享到:
评论

相关推荐

    Android.Programming.The.Big.Nerd.Ranch.Guide.2nd.Edition.0134171454.epub

    Based on Big Nerd Ranch's popular Android Bootcamp course, this guide will lead you through the wilderness using hands-on example apps combined with clear explanations of key concepts and APIs. This ...

    java编写英汉小词典

    import java.awt.*; import java.awt.event.*; import java.sql.*; import javax.swing.*; public class AddWin extends JFrame implements ActionListener { private static MySqlUtils mySqlUtils = new ...

    freemarker生成复杂word

    import java.io.OutputStreamWriter; import java.io.Writer; import java.util.HashMap; import java.util.Map; import freemarker.template.Configuration; import freemarker.template.Template; import ...

    UE(官方下载)

    This tutorial will show you how to access the information you need in your browser by simply highlighting your text in the edit window and clicking your toolbar button How to install UE3 UE3 is the ...

    VB编程资源大全(英文源码 控制)

    1.x/6.0 (Java) <END><br>6 , ocxex.zip "This is a quick example I made to show you how to use Events and properties in a OCX."<END><br>7 , news.exe This control aids as a complete Newsgroup ...

    word源码java-Code_Html:使用Eclipse开发的java项目,用于将代码转换成界面友好的html文件。Ajavaprojec

    word源码java Code_Html 本项目用于将编程语言代码源文件转换为 html 网页文件。 Html文件会根据代码的句法(比如关键字)将其以不同的颜色或字体显示, 以一种更加友好的方式显示代码。 This project is aim at ...

    ognl-2.6.7

    You can do this in two stages, parsing an expression into an internal form and then using that internal form to either set or get the value of a property; or you can do it in a single stage, and get ...

    Mahout in Action

    Running in the cloud 112 ■ Imagining unconventional uses of recommendations 113 6.7 Summary 114 PART 2 CLUSTERING ....................................................115 7 Introduction to clustering ...

    Crystal Reports Advanced v9.2(1)

    tables, and other report objects into Microsoft Outlook, Word and Excel documents - and refresh them right within the document - using Crystal Reports support for Microsoft Smart Tags in Office XP....

    ZendFramework中文文档

    Available options (for this frontend in Zend_Cache factory) 4.3.6.3. Examples 4.4. Zend_Cache后端 4.4.1. Zend_Cache_Backend_File 4.4.2. Zend_Cache_Backend_Sqlite 4.4.3. Zend_Cache_Backend_...

    基于JAVA的模拟ATM系统的设计与实现【毕业作品】.doc

    【Key word】ATM, Java, access, Eclipse 目录 摘 要 I Abstracts II 1. 绪论 5 1.1概述 5 1.2 ATM的发展 5 1.3 ATM的发展趋势 6 2. 系统分析 9 2.1 问题定义 9 2.2可行性研究 9 2.2.1 技术可行性 9 2.2.2 经济...

    CIS-263-project-1

    Check if the key is already present in the map If it is not present in the map Instantiate a new set, add this word to the set Add this key and this new set to the map else Retrieve the set ...

    一本android的好书beginning android 2 和 源码

    The Key to It All ■Chapter 34: Handling Telephone Calls Report to the Manager You Make the Call! ■Chapter 35: Development Tools Hierarchical Management Delightful Dalvik Debugging Detailed, Demoed...

    freemarker总结

    [ {“Akey”:”Avalue”},{“Akey1”:”Avalue1”}, {“Bkey”:”Bvalue”},{“Bkey1”:”Bvalue1”}, ] hashes {“you”:”a”,”me”:”b”,”he”:”c”} 注释标志 这里是注释 --> 旧版本的freemarker采用...

Global site tag (gtag.js) - Google Analytics