[java]类初始化挺有意思的题目

public class Base {
    private String baseName = "base";
    public Base() {
        callName();
    }

    public void callName() {
        System.out.println(baseName);
    }
    
    static class Sub extends Base {
        private String baseName = "sub";
        public void callName(){
            System.out.println(baseName);
        }
    }

    public static void main(String[] args) {
        Base b = new Sub();
        System.out.println(b);
    }
}

 请参考  博客  http://www.cnblogs.com/miniwiki/archive/2011/03/25/1995615.html 阅读

注意方法重写

posted @ 2018-08-07 15:42  远方的风lyh  阅读(218)  评论(0编辑  收藏  举报