The difference and use of static and final

Source: Internet
Author: User
Tags modifier

Static

Modifier variables: Static variables are initialized as the class loads, only one in memory, and the JVM allocates only one memory at a time, and all classes share static variables.

Modification method: Exists at the time of class loading and does not depend on any instance; The static method must be implemented and cannot be decorated with an abstract.

Decorated code blocks: the contents of a code block are executed after the class has been loaded.

Parent class static code block--Subclass static code block--parent class non-static code block----child class non-static code block--subclass constructor method


Final

Modifier variables:

Compile-time constants: Initialization is done during class loading and is compiled into any calculation. Can only be a basic type.

Run-time constants: The base data type or the reference data type. The reference is immutable, but the referenced object content is mutable.

Modification method: Cannot be inherited, can not be modified quilt class.

Decorated class: Cannot be inherited.

Modifier parameters: The final parameter is immutable.


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.