The usage of this keyword is as follows:
1. Call the method of this class
public String introYourself() { return this.whoAreU() + this.haoOldAreU(); }
2. Call the attribute of this class
public void changeMyName(String name) { this.name = name; }
3. Call other constructors of this class
public UserExample(String name) { this(name, -1); }
4. Call the same-name method of the parent class or other specified classes
public String whoAreSuper() { return "super is " + UserExample.this.whoAreU() + ". "; }
5. Hidden calling, without specifying the scope, java will search for variables or methods upwards in the entire class scope
public String whoAmI() { return whoAreU(); }
Recommended tutorial: Java tutorial
The above is the detailed content of Several uses of this keyword in java. For more information, please follow other related articles on the PHP Chinese website!