final Variable
If the final keyword is added before a variable, the variable cannot be changed once it is initialized.
If a final variable is a class member variable, it must be initialized and can only be initialized once.
The parameter in the method can also be a final variable. This is useful when we need to pass a reference-type variable, because sometimes we don't want to invoke the function to modify the variable to affect the value of the object in the original function. So setting a reference variable to the final type can be a valid way for the variable to be invoked to modify the parameter. You can use this variable only in the calling method, but you cannot make any modifications to it.
Copy Code code as follows:
void Test (final int a) {
Can not modify a
}
Final method
If a method in a class is final, subclasses of that class can use this method directly, but you cannot override this method.
Some compilers call the final method directly, inserting the body of the final method into the call to increase efficiency, rather than using conventional methods such as saving breakpoints and pressing stacks.
Final Class
If a class is final, then it cannot be inherited. So the final class is a leaf class and it cannot be abstract. The method in the final class is definitely final (but it does not need to be explicitly added to the final keyword in the method, and of course it doesn't matter) that the final class variable can be final or not final.