- class Foo{
- public int a = 3;
- public void addFive(){
- a+=5;
- System.out.print("f ");
- }
- }
- public class Exam01 extends Foo{
- public int a = 8;
- public void addFive(){
- this.a +=5;
- System.out.print("e ");
- System.out.println(a);
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Foo f = new Exam01();
- f.addFive();
- System.out.println(f.a);
- }
- }
复制代码 为什么输出结果是e 3
e:父类指向子类
3:这是为什么?求解 |