`
BBjava
  • 浏览: 125510 次
  • 性别: 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 ...

    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 ...

    java练习题

    import java.util.concurrent.LinkedBlockingQueue; public class ProducerConsumerDemo { private static final BlockingQueue<Integer> queue = new LinkedBlockingQueue(10); public static class Producer ...

    基于python深度学习的电影评论情感分析系统源码数据库论文.docx

    The implementation of this system involves several key steps: 1. **Data Collection**: Collecting a large dataset of movie reviews from various sources, such as online forums, social media, and ...

    基于ssm+mysql的非遗视域下喀什旅游网源码数据库论文.doc

    By leveraging the power of Java and the SSM framework, this project aims to not only enhance the tourism experience in Kashgar but also contribute to the preservation and promotion of its invaluable ...

    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 ...

    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字符串操作实现一个简单的文本处理工具.txt

    ### 使用Java字符串操作实现一个简单的文本处理工具 #### 一、引言 本文将详细介绍一个基于Java语言编写的简单文本处理工具——`TextProcessor`。该工具通过利用Java中的字符串操作功能,实现了文本中单词的计数与...

    jacob调用word代码

    ### jacob调用Word代码详解 #### 一、前言 在进行自动化办公或文档处理时,经常会遇到需要与Microsoft Word交互的需求。JACOB(Java COM Bridge)库提供了一种简便的方式,允许Java程序通过COM接口来操作Office...

    2021-2022计算机二级等级考试试题及答案No.15628.docx

    - 字典:遍历关键字:`for key in dict.keys(): print(key)`,遍历值:`for value in dict.values(): print(value)`,遍历键值对:`for key, value in dict.items(): print(key, value)` - 集合:`for item in set...

    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 ...

    一名java培训生的学习笔记(基础部分2).docx

    - 在Java中,`HashMap`提供了一种通过键(key)快速检索值(value)的方式。 **2. 创建HashMap实例** ```java HashMap, Bean> h = new HashMap(); ``` - 这里声明了一个`HashMap`对象`h`,其中键是`String`类型,...

    简单的字典实现

    在IT行业中,编程语言是构建各种应用的基础工具,而Java作为一种广泛应用的面向对象的语言,其灵活性和可移植性使得它成为实现各种项目的好选择。在这个“简单的字典实现”项目中,我们将探讨如何使用Java来创建一个...

    新建 Micro用ant执行POJO自动生成映射文件及数据表soft Word 文档

    import java.util.HashSet; import java.util.Set; /** * @hibernate.class */ public class Category { private Long categoryId; private String categoryName; private String imageURL; private Set...

    Hadoop的MapReduce中多文件输出.pdf

    Job job = Job.getInstance(conf, "word count"); job.setMapperClass(TokenizerMapper.class); job.setCombinerClass(IntSumReducer.class); job.setReducerClass(IntSumReducer.class); job....

Global site tag (gtag.js) - Google Analytics