this keyword

package Test;
/*
* Used to distinguish member variables and local variables with the same name;
* Who is calling the member, this represents who;
* When a member in a class is private, it can be obtained by the set and get methods.
*/
public class This {

  public static void main(String[] args) {
    Person p=new Person();
    p.setName("kobe");
    System.out.println(p.getName());

  }

}
class Person{
  private String name;//Because it is private, it cannot be accessed directly with p.name="kobe";
  private int age;
  public void setName(String name) {
    this.name=name;
  }
  public String getName() {
    return name;
  }

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325047325&siteId=291194637