Java this关键字用在构造方法中
Java this关键字用在构造方法中
this 关键字用在构造方法中。
[java]- 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();
- }
- }
评论暂时关闭