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

 

posted @ 2016-08-12 11:47  yasepix  阅读(238)  评论(0编辑  收藏  举报