this关键字的作用---Java

/*
当方法的局部变量和类的成员变量重名的时候,根据“就近原则”,优先使用局部变量。
如果需要访问本类当中的成员变量,需要使用格式:
this.成员变量名

“通过谁调用的方法,谁就是this。”
 */
 1 public class Person {
 2 
 3     String name; // 我自己的名字
 4 
 5     // 参数name是对方的名字
 6     // 成员变量name是自己的名字
 7     public void sayHello(String name) {
 8         System.out.println(name + ",你好。我是" + this.name);
 9         System.out.println(this);
10     }
11 
12 }
 1 public class Demo01Person {
 2 
 3     public static void main(String[] args) {
 4         Person person = new Person();
 5         // 设置我自己的名字
 6         person.name = "王健林";
 7         person.sayHello("王思聪");
 8 
 9         System.out.println(person); // 地址值
10     }
11 
12 }
原文地址:https://www.cnblogs.com/zeon/p/13338700.html