Static
1. In a class, a property decorated with static is called a static property. is common to all objects of this class, is stored in a static store, and all objects of that class can be accessed and accessed by the same variable. Can be used as a counter to count the total number of objects created.
2. In a class, a static-decorated method is not available in a static method to access non-static properties and methods, but static methods and properties can be accessed in a Non-static method, and this is not available when the static method is polymorphic.
3. Because static properties and methods belong to all objects of the class, they can be accessed using the class name. Static property/Method name---.
4.static can also modify the code block, which is executed 1 times when the class is loaded, only once.
Final
(1) The final marked class cannot be inherited
Copy Code code as follows:
Final Class t{}
Class TT extends t{}//error, final class cannot be inherited
(2) The final marking method cannot be overridden by the quilt class
Copy Code code as follows:
Class t{
Public final void function () {}
}
Class TT extends t{
public void function () {}//error, final method cannot be overridden by the quilt class
}
(3) The final mark of the local variable is constant
Copy Code code as follows:
final int x=10;
x=3//error, final tag local variable is constant and cannot be assigned
(4) The member variable of the final mark must be assigned at the same time as the declaration, or the assignment is displayed in the constructor method of the class (instance variable has no default value) before it can be used.
Such as:
Copy Code code as follows:
Class test{
Final int x=10;//declare and assign value
}
Or
Class test{
final int x;
Test () {
x=10;
}
(5) The built-in class defined in the method can only access the final type of local variables within the method, and the final defined local variable is equivalent to a constant whose life cycle is longer than the life cycle of the method run.
(6) It is also possible to define a parameter as final, which limits the range of values in the method that modifies the parameters.
There are many classes in Java that are final type: String, math, and so on.