JAVA this关键字用在构造方法中
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();
}
}
posted on 2012-01-02 06:49 java课程设计例子 阅读(186) 评论(0) 收藏 举报
浙公网安备 33010602011771号