static
1. In a class, attributes modified with static are called static attributes. It is common to all objects of this class and is stored in the static storage area. All objects of this class can access and access the same variable. Can be used as a counter to count how many objects of various types have been created in total.
2. In a class, the method modified with static is a static method. Non-static properties and methods cannot be accessed in a static method, but static methods and properties can be accessed in a non-static method; and the static method polymorphism is invalid and cannot Use this.
3. Since static properties and methods belong to all objects of this class, they can be accessed using class name.static property/method name---.
4.static can also modify the code block, which will be executed once and only once when the class is loaded.
final
(1) Classes marked final cannot be inherited
class TT extends T{}//Error, final class cannot be inherited
public final void function(){}
}
class TT extends T{
public void function(){}//Error, final method cannot be overridden by subclasses
}
like:
}
//or
class Test{
final int x;
Test(){
x=10;
}
(6) It is also possible to define a formal parameter as final, which limits the value range of the formal parameter that can be modified in the method.
There are many classes in java that are final types: String, Math, etc.