标签:ons 编译 结果 div 总结 静态 str 代码块 父类静态
public class test {
static class A {
public static String name = "hello";
static {
System.out.println("A static block1"); //1
}
{
System.out.println("A block3"); //3
}
public A() {
System.out.println("A constructor4"); //4
}
}
static class B extends A {
public static String childName = "hello";
static {
System.out.println("B static block2"); //2
}
{
System.out.println("B block5"); //5
}
public B() {
System.out.println("B constructor6"); //6
}
}
public static void main(String[] args) {
new B();
}
}以上运行结果为:子类的非静态代码块运行完成再去运行子类的构造方法,这个就是一个对象的初始化顺序。
标签:ons 编译 结果 div 总结 静态 str 代码块 父类静态
原文地址:http://www.cnblogs.com/lytwajue/p/6928964.html