菜鳥請教

來源: 未知未覺 2012-03-18 12:38:31 [] [博客] [舊帖] [給我悄悄話] 本文已被閱讀: 次 (550 bytes)
本文內容已被 [ 未知未覺 ] 在 2012-03-18 12:39:25 編輯過。如有問題,請報告版主或論壇管理刪除.

菜鳥請教一個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? 

請您先登陸,再發跟帖!

發現Adblock插件

如要繼續瀏覽
請支持本站 請務必在本站關閉/移除任何Adblock

關閉Adblock後 請點擊

請參考如何關閉Adblock/Adblock plus

安裝Adblock plus用戶請點擊瀏覽器圖標
選擇“Disable on www.wenxuecity.com”

安裝Adblock用戶請點擊圖標
選擇“don't run on pages on this domain”