The initialization Object Sequence in Java, the usage of Static code blocks, and the usage of Static code blocks
(1) differences between static methods for java static code blocksGenera
"System.out.println", which is used extensively in the preceding. Where system is a predefined class of systems, out is a static member of it, and println is an instance method of out.The order of initialization in 6.JavaThe first time a Java class is loaded, a
Java internal class (InnerClass) ---- non-static internal class, static internal class, local internal class, anonymous internal classMany people are not familiar with the
1. Static initialization block Static initialization blocks are only executed once when the class is first loaded , while static initialization blocks can only assign values to
Some member variables have special data types and their initialization methods are different from those of common data types. These special types of member variables include:
A. Reference
B. Constants
C. Static
D. Static constants (integer)
E. Static constants (non-integer)
Constants and references must be initialized
First, the Java object initialization process The first step is to load the class , where a Java object will load class before initialization, generating class objects in the JVM. Loadi
First, describeStatic code blocks for classes in Java, Construction code blocks, constructor methods, initialization order of static members: First , when the class is loaded, allocate the memory space for the static member variable in the
There are two types of member variables for the ①java class: A variable that is modified by the static keyword, called a class variable or static variable Another no static modifier, for member variables ② popular Point said: Th
Java Initialization Order1 The class is loaded first when you start an instance of new B. (Classes are loaded by the Java class loader only when they are created with the new call)2, when loading the class, first load the parent
Static modified variables and methods belong to the class, allocating space in memory when the class is loaded;Call can be called directly through the class name, when the object is changed by creating a static variable, then the static
instance domain, the program will still initialize the domain to the default value, and then execute the initialization statement or instance block in the order in which the code appears in the class. If the instance block position is in front of the initialization statement, even if it changes the value of the field, it will be changed back by the
.
Static Initialization is performed only when necessary.The initialization sequence is static first (if they are not initialized by the previous object creation process), followed by non-static objects.
It is necessary to summarize the object creation process here. Consider
Case without parent class1, static code blocks--Static member variables--member variables (instance properties)--code block--constructors2, static code blocks and static member variables are initialized only onceThere are cases of parent class1, parent class non-objectStatic
the initialization code for that instance. The order of execution is the same as the order in which they are arranged in the source program. The format is:
Class Name {
[modifier]{//modifiers can only be static or nothing (nothing is known as a constructor initialization block or directly called an
Initialization and features of static members in the C ++ class
Some member variables in the C ++ class are initialized differently from those in the general data type. The following test compilation environment is:
➜ g++ -vUsing built-in specs.COLLECT_GCC=g++Target: x86_64-linux-gnugcc version 5.4.0 20160609 (Ubuntu
Up-depth Java virtual machine- - deep Java Virtual Machine (ii)--Class loader details (above), in the previous article, we explained the life cycle of the class loading and linking, this one we went on to look down. initialization of the
variable for a class, a static method, and a construction Method-the constructor method is also static. This feature of Java is called: dynamic loading .
It is necessary to differentiate between loading and initialization, loading a
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.