The class initialization phase is the last step in the loading process, where the variable has already assigned the initial value of the system requirement, and during the initialization phase, the class variables and other resources are initialized according to the programmer's subjective plan, or from another angle:
Remember: Static data members are usually declared in the class declaration and initialized in files containing Class methods. during initialization, the scope operator is used to indicate the class to which the static member belo
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
does not define final, then when the outer class method executes, The local variable must be gc, but a method of the inner class has not been executed, and the external variable that he refers to cannot be found. If defined as final,java, this variable is copied as a member variable inside the inner class, so that the
In general, the initialization of static members of C + + classes is not difficult to understand, but refers to the "in-class initialization" of C + + static members that is confusing.Let's look at the following code:1 //example.h2#include 3#include 4 using namespacestd;5 6
class, and cannot directly access non-static members in the classes. This is because, for non-static methods and variables, you need to create an instance object of the class before you can use it, and the static method does not have to create any objects before it is used.
Some member variables have a special data type, and they are initialized differently from the member variables of the normal data type. These special types of member variables include:A. ReferencesB. ConstantsC. StaticD. Static constants (integer type)E. Static constants (non-integral type) constants and references, which must be initialized through a parameter list. The
Original: http://www.javaworld.com/article/2077372/learn-java/static-class-declarations.htmlTo understand the use of the static keyword in a class declaration, we first need to understand the class declaration. There are two kinds
1. Static data members are declared in the class declaration and initialized in the file containing the class method. Initializes the class that the static member belongs to by using the scope operator. However, if the static memb
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
anonymous classes without the class keyword?1) to have the new operator, similar to the normal class instantiation of an expression.2) to implement an interface or inherit a class, the example above is to implement the HelloWorld interface.3) class body (body), where you can define fields, methods, or even partial cla
the time of instantiation, so the attribute is initialized, it also meets the conditions that need to be initialized when it is allocated memory space and will not be changed later.
Article 4: When a class attribute is modified to static and final at the same time, it belongs to the class resource, when the class is l
2014.9.2 Why does the reference of the static method of the parent class through subclass not cause subclass initialization? See the following program: Class superclass { Static { System. Out. println ("superclass init "); } Public
Error: ISO C + + does not allow the initialization of a very static member within a classstarting today to learn C + + primer, when involved in the sales_item.h header file, there are some problems (and c++11 new features related), the current compiler version is gcc/g++ 4.6.3, so need to upgrade. You can use the PPA to upgrade to 4.8.1, as follows:sudo add-apt-repository ppa:ubuntu-toolchain-r/testsudo apt
The static member variables and const constants of the C ++ class must be initialized when defining the class; otherwise, compilation errors will occur.
The initialization method is as follows:
C ++ class static member variable
First, the static variable is initialized only once, whether in the class or in the function... there is such a function:
Void Foo ()
Here, static int A = 3 is executed only once. Call Foo () twice in main and the result is 34. Change the above function
Void Foo ()
It is also called twice in Foo (). The result is 33.
Use non-const
The definition of static member variables consists of two parts.
Like a function, you must first declare it in the class, and then find another place to implement it. Static members must first declare it in the class, and then "IMPLEMENT" outside the class.
This
Source: Click to open the link
The order of Java class initialization is often confusing, and now this article tries to give the JVM an explanation by experimenting with the initialization order of classes in the Java non-inheritance and inheritance relationships from the JV
A netizen asked:
"
In a class, there is a member variable static set
"
The initialization of special member variables in a class is very skillful. I wrote a blog post on this issue:
Initialization of member variables of Special Data Types
However, this blog does not
ask, why not print run parent static code. Because the value variable is a constant value that has been determined at compile time with the class. class file is a reason, so do not print.Note: The compile-time constant must meet 3 conditions: Static, Final, constant.[HTML]View Plaincopyprint?
pre
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.