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