菜鸟请教

来源: 2012-03-18 12:38:31 [博客] [旧帖] [给我悄悄话] 本文已被阅读:

菜鸟请教一个java的基础面试题。

 
------------------------------------------------------
public class D
{
 public int a=10;
 public int test() { return a; }
}
------------------------------------------------------
public class E extends D
{
 public int a=20;
 public int test() { return a; }
}
------------------------------------------------------
Now suppose 
 
D d=new E();
 
So d.a = ? and d.test()=?
 
I understand d.test() is 20, due to inheritance finds the lowest level method and call.
But why d.a is 10?