|
补充。。。Re: Re: 纠正!
最初由 long_biti 发布
[B]
=======================================
下面一段摘自<thinking in java-3e>
It’s helpful to summarize the process of creating an object. Consider a class called Dog:
The first time an object of type Dog is created (the constructor is actually a static method), or the first time a static method or static field of class Dog is accessed, the Java interpreter must locate Dog.class, which it does by searching through the classpath.
As Dog.class is loaded (creating a Class object, which you’ll learn about later), all of its static initializers are run. Thus, static initialization takes place only once, as the Class object is loaded for the first time.
When you create a new Dog( ), the construction process for a Dog object first allocates enough storage for a Dog object on the heap.
This storage is wiped to zero, automatically setting all the primitives in that Dog object to their default values (zero for numbers and the equivalent for boolean and char) and the references to null.
Any initializations that occur at the point of field definition are executed.
Constructors are executed. As you shall see in Chapter 6, this might actually involve a fair amount of activity, especially when inheritance is involved. [/B]
Think in java(3e)说的很清楚:
1、Dog对象首次被产生出来,或者他的static 函数或者数据成员被访问,java interpreter去找出Dog.class
2、Dog.class被装载所有的初始化被执行(all of its static initializers are run)
3、new dog()在堆上分配空间
4、存储空间被清零,对象内的数据被赋予初值。(This storage is wiped to zero, automatically setting all the primitives in that Dog object to their default values (zero for numbers and the equivalent for boolean and char) and the references to null. )
5、执行所有发生在数据定义处的初始化动作。(Any initializations that occur at the point of field definition are executed. )
6、执行构造函数(Constructors are executed. ) |
|