java-this关键字

  1.  (1)this调用本类中的属性,也就是类中的成员变量;
        this.name=name;
     (2)this调用本类中的其他方法;
     (3)this调用本类中的其他构造方法,调用时要放在构造方法的首行。
    public class Student { //定义一个类,类的名字为student。 
     public Student() { //定义一个方法,名字与类相同故为构造方法
         this(“Hello!”);
     }
     public Student(String name) { //定义一个带形式参数的构造方法
     }
    }
    
    

     

    4)返回实例本身
        return this;

     

posted on 2019-02-20 19:32  手握太阳  阅读(150)  评论(0编辑  收藏  举报

导航