有关java 继承和多态的问题
请看如下代码:
public class Base { // 父类Base
int i=1;
public void amethod(){
System.out.println("Base.amethod()");
}
public Base(){
this.amethod();
}
}
public class Descend extends Base { // 子类Descend
int i=-1;
public static void main(String[] arg){
Base b=new Descend();
System.out.println(b.i);
b.amethod();
}
public void amethod(){
System.out.println("Descend.amethod()");
}
}
为什么运行结果是
Descend.amethod()
1
Descend.amethod()
而不是
Base.amethod()
-1
Descend.amethod()
请各位大虾帮忙分析分析