Java programming things 66-Final Modifier
Chen yuefeng
From:Http://blog.csdn.net/mailbomb
8.7.2 final
The final keyword is the final and final meaning. It can be used in a program to modify the declaration of classes, member variables, and methods. The content modified by this keyword is immutable.
8.7.2.1 final data
The final modified data is a constant. constants can appear inside the class, or inside the method or constructor. Constants can be assigned only once in a program.
For other descriptions, see the preceding constant description.
In a program, the member constants inside a class are modified using the static modifier to facilitate calls. The sample code is as follows:
/**
* Constant usage
*/
Public class student {
/** Gender */
Int sex;
/** Male */
Public final static int male = 0;
/** Female */
Public final static int female = 1;
}
8.7.2.2 final Method
The final keyword can also modify the method. The final modifier is called the final method. The final method cannot be overwritten, that is, the method cannot be overwritten within the subclass.
The final modification method can improve the execution speed of the method to a certain extent. Therefore, the overwrite judgment is not required when the method is called.
8.7.2.3 final class
The final keyword can also modify the class. The final modified class is called the final class. The final class cannot be inherited, that is, the class cannot have subclasses.
Each method in the final class is a final method.
8.7.3 native
The native keyword is "local". The native modifier is implemented only by the method declaration in Java, and the code inside the method is implemented in other languages within the Java Virtual Machine.
Generally, native methods are related to system operations, or are more efficient based on the underlying implementation. They are common in the system class. For example, the arraycopy method of the system class.