java-se - Java:请教这段代码的执行顺序(如图)?万分感谢
大家讲道理
大家讲道理 2017-04-18 10:37:26
0
2
256
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
Peter_Zhu

I have read an article before that talks about this order issue. importNew上面的,找了找没找到。类加载都是先加载父类的static属性和块,然后加载本身的static属性和块,顺序都是从上往下的。构造对象的时候,总是先调用父类的构造器,然后调用自身的构造器。你上面的例子,首先加载App类,谁想它第一个static属性竟然需要构造一个自身类型的对象,这就直接跳过其他static属性和块到了App的构造器了,构造器里本身就一句要打印一个4,但是程序在编译后会把SubClass t = new SubClass();加入到构造器上方的,这个你可以查看一下编译生成的字节码文件,然后转而去加载和构造SubClassObjects and order are all mentioned above.

大家讲道理

Can you do breakpoint debugging? You can use eclipse breakpoints to debug and see the execution sequence of the code and snapshots of the data

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template