Java keyword final, static usage summary

Source: Internet
Author: User

Original http://lavasoft.blog.51cto.com/62575/18771/

Feel the original is too messy. Refine it, please. Please correct me.


Static
1. Modify methods and variables (to be static variables, static methods), or to form static blocks of code (cannot appear in the method, other places can be seen)
2. Modifying variables, sharing the same variable
3. Modification method, cannot invoke non-static member, cannot contain abstract object (because static member class is effective when loading, abstract object does not take effect contradiction)
4. Static code block, cannot call non-static members, cannot contain abstract objects, can be any position (except no longer inside the method)
5. Call directly through the class name. Method name/variable name
Final
1. Modifying classes, variables, methods
2. The modifier class indicates that it cannot be inherited, and there are no subclasses
3. Modifier variables represent constants
4. The modification method means that the inheritance cannot be overridden and the construction method cannot be modified.
5.fianl method parameter void F1 (final int i) {} means that within a method I is a constant
Static final
1. Modifier variables represent global constants
2. The modification method represents a static method that cannot be overwritten, and cannot have non-static members and objects that are not instantiated


This article from "Qiang Qiang" blog, declined reprint!

Java keyword final, static usage summary

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.