The final keyword can modify local variables in classes, member variables and methods. You can use the keyword final to declare a class as a final class. A final class cannot be inherited, that is, it cannot have subclasses.
For example:
finalclassA{…}
A is a final class and no class will be allowed to be declared as a subclass of A. Generally, some classes are modified as final classes for security reasons. For example: The String class provided by Java in the java.lang package plays a very important role in the normal operation of the compiler and interpreter. Java does not allow user programs to extend the String class, so Java modifies it as a final class.
If a method in the parent class is modified with final, then this method is not allowed to be overridden by subclasses, that is, subclasses are not allowed to hide the final methods that can be inherited.
If a member variable or local variable is modified to be final, it is a constant. Since constants are not allowed to change during runtime, constants have no default value when declared, which requires the program to specify the value of the constant when declaring it.