This keyword in the class, this keyword
This can be used to distinguish between local variables and member variables, because if this. member variable = parameter value is used in the constructor,
The initialization value can be assigned to the member variable when the new object is created. Otherwise, the assignment fails,
Therefore, this can distinguish between member variables and local variables.
Class person {private String name; person (String name) {name = name; // The default value of the member variable name is null, assign a value to the local variable} person (String n) {name = n; // The member variable is assigned a value at this time} // when the value is assigned, if the parameter name and member variable name are the same, find the local variable and assign a value. If they are different, find the member variable. If the assigned object is not a member variable or a parameter name, the error "person (String name) {this. name = name; // normal value }}
This feature: when an object calls the function of this, this indicates the object, that is, this actually refers to the specific object with new.
Use this to call other constructors in the constructor: this (list of constructor parameters to be called); and The this () statement should be placed in the first row of the constructor that calls other constructor.