The This keyword in Java refers to the current object, which can be used to invoke the current object's member variables directly or directly with the current object's member method, this is our common scenario, then there is no other situation!
This can also be used in the construction of the parameterless method directly with a parenthesis, thus invoking the construction method of the parameter, so that when we re new to another object, we can no longer be initialized by the construction method of a parameter, directly through the construction method without parameters immediately.
The code is as follows:
Public classStudent {PrivateString name = "Zhang San"; Private intsum = 0; PublicStudent () { This("Harry");//calling a constructed method of a parameter } PublicStudent (String name) { This. name = name;//call the name in the member variable to distinguish the name in the method } Public voidsay () {System.out.println ( This. Name); } /*** Recursive summation *@paramNum*/ Public voidSumintnum) { This. sum + = num--; if(0 <num) {sum (num); } Else{System.out.println ("sum =" +sum); This. Say ();//Call member Method say () } } }
Java the use of the This keyword