super的问题
class A { public String name = "01"; } class B extends A { public String name = "02"; public void testM() { //System.out.println(this.name + "," + super.name); System.out.println(this.getClass().getSimpleName() + "\n" + super.getClass().getSimpleName()); } } class ThisSuper { public static void main(String[] args) { B b = new B(); b.testM(); } }
输出结果:
B B
super既然指向子类的父类引用,为什么程序打印出子类呢?