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关键字用在构造方法中
最新推荐文章于 2024-11-04 11:42:18 发布
本文详细解释了Java构造方法中使用this关键字的作用及其实现原理,通过实例展示了其在构造方法重载中的应用。
2万+

被折叠的 条评论
为什么被折叠?



