One. this keyword
Refers to the current object's reference, most of which is used to solve the problem of the name of the passed parameter and member variable;
For example, a SetName method is defined in a class that assigns the parameter value of a method to a member variable in the class:
public void SetName (String name) {
THIS.name = name;
}
This refers to invoking the other constructor methods in the current class, but when using the this method in the parameterless constructor method, this is the first sentence to be written in the non-parametric method.
Two. Static keyword
When two classes share a variable, the static modifier is used, and static is represented statically, and can be decorated with variables, constants, methods, and classes.
Format: Class name. Static Class Member
1. The variable or constant is stored in the data area, not in the stack or heap; no matter how many objects are instantiated, all objects share one copy, and static modified variables do not need to be instantiated at the time of access, and the class name is taken out directly.
2. When modifying the method, it is convenient and often used as a tool class because it does not need to be instantiated.
3. Static methods cannot access non-static members and cannot use the This keyword.
Three. Final keyword
The meaning is final, representing the constant
1. Modify the variable to become a constant, can only be assigned once, and must be assigned when defined, the variable name needs to be capitalized;
2. Cannot be overridden when modifying a method;
3. Cannot be inherited when modifying classes; String class comes with final;
Four. Inheritance of classes
Inheritance is a subclass that has a member of the parent class;
Format: modifier (optional parameter) class subclass name extends parent class name {
Class Body
}
Five. Inheritance rewriting (Override/overwrite): It embodies the ability of subclasses to live to change the methods of the parent class;
Overridden Condition:
1. There must be inheritance;
2. Method names are the same;
3. Parameter list (parameter type, parameter number consistent);
4. The return value type is the same;
5. Subclasses overriding the parent class cannot use more restrictive access than the parent class;
Java Fundamentals 7-Object Oriented 2