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(); } }

你可能感兴趣的:(JAVA this关键字用在构造方法中)