在Java中,经常可以看到this,this关键字在程序中的意思和他的翻译很接近, 确切的说他在方法内部就是这个方法所属的对象的引用变量。例如
student stu1=new student (小黑)
public class Student {
private String name ;
public student(String name ) {
this.name=name;
}
}
student stu1=new student 这句话调用了Student的构造方法,
this 就是对象stu1, student stu1=new student (小黑) 等价于this.name=name;
为什么要用this那,因为可能会创建很多的Student对象,在用的额时候,我们不能记得那么准确,除非去翻,但是太麻烦了,所以我们把不不知道名字的对象用this来替代
重点来了
不用静态方法修饰,就可以用this ,用static修饰的属于类
this的主要作用是区分类(成员)变量与局部变量名相同的变量
但是,this不是调用的,this.就是指类(属于类),