java实例变量及方法调用顺序

public class Base {
    private String name="base";

    public Base(){
        sayHello();
    }
    void sayHello() {
        System.out.println("Base hello " + name);
    }
}

class Derived extends Base {
    private String name="Derived";

    public Derived(){
        sayHello();
    }

    void sayHello() {
        System.out.println("Derived hello " + name);
    }
}

public class Main {
    public static void main(String[] args) {
        Base b = new Derived();
    }
}
Derived hello null
Derived hello Derived
原文地址:https://www.cnblogs.com/yasepix/p/5764365.html