您的位置:首页 > 编程语言 > Java开发

JAVA this关键字用在构造方法中

2012-01-02 06:49 295 查看
this 关键字用在构造方法中。

package com.han;

/**
* this 关键字用在构造方法中。
* @author han
*
*/
public class ThisUse {

public ThisUse() {
this("this调用无参构造方法之前先调用有参构造方法");
//it is equivalent to : new ThisUse("this调用无参构造方法之前先调用有参构造方法");
System.out.println("this调用无参构造方法");
}
public ThisUse(String name) {//构造方法重载
System.out.println(name);
}

@SuppressWarnings("unused")
public static void main(String[] args) {
// TODO Auto-generated method stub
ThisUse object=new ThisUse();
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: