From http://www.cnblogs.com/ggjucheng/archive/2012/11/28/2793257.html
Preface
In an instance method or constructor, This references the object pointing to the current object-method call or constructor call. You can use this to reference any member in the instantiation method or constructor.
Use this in the field
The most common reason for using this keyword is that the field is hidden by parameters of the method or constructor.
For example, the point class is written as follows:
Public ClassPoint {Public IntX = 0;Public IntY = 0;//ConstructorPublicPoint (IntA,IntB) {x=A; y=B ;}}
However, it can also be written as follows:
Public ClassPoint {Public IntX = 0;Public IntY = 0;//ConstructorPublicPoint (IntX,IntY ){This. X =X;This. Y =Y ;}}
Each parameter of the constructor hides the object field. In the constructor, X is the local copy of the first parameter of the constructor.Point field X. The constructor must use this. X.
Use this in the constructor
In the constructor, you can use the this keyword to call another constructor of the class. This is an explicit constructor call. Here isRectangle class:
Public Class Rectangle { Private Int X, Y; Private Int Width, height; Public Rectangle (){ This (0, 0, 0, 0);} Public Rectangle ( Int Width, Int Height ){ This (0, 0 , Width, height );} Public Rectangle ( Int X, Int Y, Int Width, Int Height ){ This . X =X; This . Y = Y; This . Width = Width; This . Height = Height ;}...}
This class has a series of constructor methods, each of which is initialized.Rectangle
Department variable. If no initialization value is provided for the parameter, the constructor provides the default value for each member variable. For example, if there is no parameter constructor, four parameters with 0 values are input, and the constructor of the four parameters is called. There are two constructor methods for the parameters, and two 0 parameters are input, call the construction method of the four parameters. As mentioned before, the compiler determines which constructor to call based on the number and type of parameters.
If so, the call to another constructor must be the first line in the constructor.