The opening of the garden has been a while, but in addition to the first day vowed to send two essays, then no later. Now think about, one does not know what to write, and secondly lazy too strong, too procrastination. The reason why I think of the garden today is that I have solved a very important problem today (my feeling), and I have not found the answer that is easy to understand, title!
"This", many of the online posts said too professional, read is also confused. Today's code is clear.
First, look at the following code:
Public class Test () { publicint A; //Output statement THIS.A refers to this a Public void Test () { int//Does not add this call to this a System.out.println (a);
System.out.println (THIS.A);}}
look at the note (the note is added behind me, so look at the irregular), it is so simple. If you don't see it, I'll say a few more words.
1, there are two variables in this code are "a", and one is a member variable , and the other is a local variable . There is a test () method with local variables A and two output statements !
2, if there is no this, the program defaults to call a in the test () method, to call the test () class in the member variable of a is required to use this, that is, THIS.A;
3, this keyword can only appear in the method !
4. This keyword can only be used to access member variables ! If the member variable is not, an error will be provided.
The first time to write technical stickers, you are welcome to ask more opinions
The This keyword in Java