Java programming things 66-Final Modifier

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.