类的创建过程(摘抄与java编程思想)

来源:互联网 发布:假人交友app源码 编辑:程序博客网 时间:2024/06/06 14:01
早上又起来看了下java编程思想(英语和java兼得),关于类的创建过程,之前也没有在写程序的时候,也就从来没有去想过到底是怎么的一回事,反正是new一个!然后就去用!今天在书里看到这么一段的内容摘抄下来
1.Even though it doesn't explicitly use the static keyword,the constructor is actually a static method.So the first time an object of type Dog is created,or the first time a static method or static field of class Dog is ccessed,the java interpreter must locate Dog.clss,which it does by searching through the classpath.
(
尽管它没有明确地使用static关键词,构造函数实际上是一个static方法。所以当第一次这个Dog的对象被创建或者第一次static方法或静态域被访问时,java将会通过classpath去加载Dog.class
)
2.As Dog.class is loaded,all of its static initializers are run.Thus,static Initialization takes
place only once,as the Class object is loaded for the first time.
(
当Dog.class被加载时,所有的静态内容进行初始化,初始化的过程只发生在类被第一次加载的时候
)
3.When you create a new Dag(),the construction process for Dog object first allocates enough storage for a Dog object on the heap.
(
当你创建一个Dog时,在个过程中会为这个对象在堆中分配足够的存储空间
)
4.This storage is wiped to zero,automatically setting all the primitives in that Dog object to their default values and the references to null.
(
而这块区域中的内容将被清零,自动的为基本数据类型赋予默认值,为引用赋予null
)
5.Any initialization that occur at the point of field definition are executed.
(
然后执行对这些成员域(属性)的初始化/*4和5不是相同的过程,首先所有的属性都会先被赋予默认值,然后再根据程序员的意图进行初始化*/
)
6.Construtors are executed.As you shall see int the Reusing Classes chapter,this might actually involve a fair amount of activity,expecially when inheritance is involved.
(执行构造函数)
原创粉丝点击