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

早上又起来看了下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.
(执行构造函数)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值