Static
We use the static keyword in two special cases:
① we want to use a store to hold a specific data, no matter how many objects you want to create, or if you don't create the object at all.
② We need a special method that is not associated with any of the methods of the class.
public class Staticinjava { static int i = N; static void Statictest () { staticinjava.i++; }}
Final
Before we talk about final, let's start by talking about the concept of "constant":
① compile-time constants, never change.
② the runtime Initializes a value, and we do not want this value to change.
Final data
For the base data type, final turns the value into a constant. For an object handle, final changes the handle to a constant, but the object that the handle points to is itself modifiable.
You can set the argument to the final property, and within this method, you cannot change the handle that the argument points to.
Final method
The inherited class cannot overwrite or overwrite this method by adding the final keyword to the method.
The compiler automatically replaces the method call with a copy of the actual code in the final method.
Final class
The final method for the class is not allowed to inherit.
Static and final keywords