牛客网Java笔记(一)

时间:2022-01-11 19:37:04

1.下面代码运行结果为:

class B extends Object {
    static
    {
        System.out.println("Load B");
    }
    public B()
    {
        System.out.println("Create B");
    }
}
class A extends B {
    static
    {
        System.out.println("Load A");
    }
    public A()
    {
        System.out.println("Create A");
    }
}

public class Testclass {
    public static void main(String[] args)
    {
        new A();
    }
}

tips:父类静态代码块-》子类静态代码块-》父类构造代码块-》父类构造函数-》子类构造代码块-》子类构造函数,所以结果为:Load B -> Load A ->Create B ->Create A