Java's usage of the this keyword, javathis keyword
The this keyword in Java indicates the current object. You can use it to call the member variables of the current object or call the member methods of the current object directly. this is a common scenario, is there any other situation!
This can also directly enclose parentheses in the constructor without parameters to call the constructor with parameters. In this way, when we create a new object, instead of initializing through the construction method with parameters, you can directly use the construction method without parameters.
The Code is as follows:
Public class Student {private String name = "Zhang San"; private int sum = 0; public Student () {this ("Wang Wu "); // call the construction method with parameters} public Student (String name) {this. name = name; // call the name in the member variable to distinguish the name} public void say () {System. out. println (this. name);}/*** recursive summation * @ param num */public void sum (int num) {this. sum + = num --; if (0 <num) {sum (num);} else {System. out. println ("sum =" + sum); this. say (); // call the member method say ()}}}