Home > Java > JavaBase > Several uses of this keyword in java

Several uses of this keyword in java

王林
Release: 2019-11-13 16:29:25
Original
5415 people have browsed it

Several uses of this keyword in java

The usage of this keyword is as follows:

1. Call the method of this class

public String introYourself() {
 return this.whoAreU() + this.haoOldAreU();
}
Copy after login

2. Call the attribute of this class

public void changeMyName(String name) {
 this.name = name;
}
Copy after login

3. Call other constructors of this class

public UserExample(String name) {
 this(name, -1);
}
Copy after login

4. Call the same-name method of the parent class or other specified classes

public String whoAreSuper() {
 return "super is " + UserExample.this.whoAreU() + ". ";
}
Copy after login

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();
  }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template