This article illustrates the usage of this keyword in Java and shares it for your reference. The specific analysis is as follows:
One, this use scope
1. The This keyword, used in the method definition of a class, represents a reference that invokes the method object.
2. Use the keyword this when you must indicate who is the object of the current use method.
3, sometimes use this can handle the case of the member variable and the name of the parameter in the method.
4, this can be considered as a variable whose value is the reference to the current object.
Note: This generally appears in the method when the method is not invoked. Don't know this points to that specific object.
When an object invokes a method with this, this points to the object that called the method.
Second, the program code is as follows:
public class testthis{
private int i;
Public testthis (int i) {
this.i = i;
}
Private Testthis Increment () {
i = 1;
return this;
}
public static void Main (string[] args) {
testthis mtestthis = new Testthis (MB);
System.out.println (Mtestthis.increment (). Increment (). i);
}
The output is shown in the following illustration:
I hope this article will help you with your Java programming.