A This keyword
The This keyword can appear in a constructor method and an instance method, not in a static method, because a static method can be called with the class name, and there may not be any objects present.
This is used in two main ways:
1 in the constructor method, call the other constructor methods of this class. The format is this ([argument list]); When you call the other constructor methods of this class through this, the statement must appear in the constructor method and must appear as the first statement.
2-generation refers to the current object
For example:
1 Public classPerson {2 3 PrivateString name;4 5 Private intAge ;6 7 PrivateString gender;8 9 PublicPerson () {//Construction Method OneTen One } A - PublicPerson (String name,intAge) {//Construction Method Two - the This(Name, age,NULL);//Use the This keyword to invoke the constructor method in this class three - - } - + PublicPerson (String name,intAge1, String gender) {//Construction Method Three - + This. Name =name; Because the parameter is the same as the member variable name in the class, this.name is used to represent the member variable A atAge =Age1; Because the parameter differs from the member variable name in the class, it can be impractical this.age, directly with age = Age1 - - This. Gender =gender; - - } - in}
Two Super Keywords
There are two uses of the Super keyword:
1 using the Super keyword in the constructor method of a subclass to invoke the constructor of the immediate parent class, the Super statement must be the first sentence in the constructor method of the subclass. If you do not use the Super keyword in a subclass, the system defaults to calling the parent class with no arguments, that is, the implicit use of super (), the statement, and notice that the parent class must have a parameterless construction method.
2 Use the Super keyword to invoke member variables and methods that are hidden by the quilt class. If a child class defines a member variable that has the same name as the parent class, the subclass hides the member variable that inherits from the parent class. If a child class defines a method that is exactly the same as a method defined by the parent class, the method inherited from the parent class is completely hidden (i.e. override, overwrite).
Use of the super and the This keyword in Java