Static, final, and static final usage

Source: Internet
Author: User

1. Scope of use: Class, method, and variable.

2. Differences and contacts:

2.1.static: static. The methods and attributes modified by static only belong to any object that does not belong to the class.
2.2.static usage:
2.2.1.static can be used to modify [internal classes], methods, and member variables.
2.2.2.static [do not modify external classes] and [do not modify local variables] (because static itself is defined as Class-level, so local variables cannot be modified using static ).

2.3 final meaning: [only one value can be assigned.
2.2.final usage:
2.2.1.final indicates that the attribute can only be assigned once. (1) basic type: the value cannot be modified; (2) reference type: the reference type cannot be modified.
2.2.2.final indicates that the method cannot be overwritten, but can be accessed by the quilt class (if the method is not private ).
2.2.2.final indicates that the class cannot be inherited.

3. Joint Use of static final

. Applicability:

3.1.2. the intersection of the two ranges can only be modified: member variables, methods, and internal classes.

. Meaning: it is also the intersection of the two:
3.2.1. Method: Method of the class and cannot be overwritten.
3.2.2. member variable: a variable of the class and can be assigned only once.
3.2.3. Internal class: It belongs to an external class and cannot be inherited

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.