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;

猜你喜欢

转载自www.cnblogs.com/jiangtao1218/p/10408598.html