java--static Keyword Summary

Source: Internet
Author: User
Tags modifier

Static (statically)

Can be used to modify properties, methods, blocks of code (or initialization blocks), inner classes

Static modifier property (class variable):
    • 1. All objects created by the class share this property
    • 2. When one of the objects modifies this property, it causes another object to make a call to this property. VS instance variable (non-static decorated property with each object owning a set of replicas)
    • 3. Class variables are loaded with the load of the class, and the uniqueness
    • 4. Static variables can be called directly from the "class. Class variable" form.
    • 5. The class variable is loaded earlier than the object. So when you have an object, you can use the object. Class variable. However, "class. Instance variable" is not possible.
    • 6. Class variables exist in the static domain.
Static Modification method (class method):
    • 1. Loaded with the load of the class, in memory is the only
    • 2. Can be called directly through the "class. Class method" mode.
    • 3. You can call a static property or a static method internally, and you cannot invoke a non-static property or method. Conversely, a non-static method can call a static property or a static method

Note: static methods are not allowed to have this or super keyword!
  The life cycle of static structures (static properties, methods, blocks of code, inner classes) is older than non-static structures, while being recycled is later than non-static structures

Static modifier code block (block code):
    • 1. There can be output statements inside
    • 2. Loaded with the load of the class and loaded only once
    • 3. Multiple static code blocks executed in sequential structure
    • 4. Static code blocks are executed before the execution of non-static code blocks.
    • 5. Static structures (class properties, class methods) can only be executed in a code block
static modifier inner Class (Statically inner Class):
      • 1 It is created without the need to rely on the perimeter class.
      • 2 It cannot use non-static member variables and methods of any perimeter class.

java--static Keyword 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: 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.