[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 阅读
注意方法重写