日期:2014-05-20  浏览次数:20652 次

一道SCJP考试题 大家帮帮忙
答案是哪两个?   为什么呢?


Given:
10.   public   class   Money   {
11.   private   String   country,   name;
12.   public   getCountry()   {   return   country;   }
13.}
and:
24.   class   Yen   extends   Money   {
25.   public   String   getCountry()   {   return   super.country;   }
26.   }
27.
28.   class   Euro   extends   Money   {
29.   public   String   getCountry(String   timeZone)   {
30.   return   super.getCountry();
31.   }
32.   }
Which   two   are   correct?   (Choose   two.)
A.   Yen   returns   correct   values.
B.   Euro   returns   correct   values.
C.   An   exception   is   thrown   at   runtime.
D.   Yen   and   Euro   both   return   correct   values.
E.   Compilation   fails   because   of   an   error   at   line   25.
F.   Compilation   fails   because   of   an   error   at   line   30.


答案是哪两个?   为什么呢?

------解决方案--------------------
12行沒有返回值的話,那有n個錯誤了
------解决方案--------------------
请LZ检查一下
------解决方案--------------------
Money的public getCountry() { return country; } 是不是少了String.
如果这样的话,B,E为正确答案.Money 的country为private,不能直接进行访问,必须通过公有的方法访问.
------解决方案--------------------
阅过,同意楼上的
------解决方案--------------------
应该是AB吧。。。?
------解决方案--------------------
应该是BF
------解决方案--------------------
答案是:B和E
Money 的country属性的访问权限为private,所以它在其派生类(Yen和Euro)中不可见(虽然这两个类中都为country分配了内存空间),所以不能在Yen派生类中直接访问super.country.
而在派生类Euro中调用super.getCountry()可以,因为他的访问权限为public.
------解决方案--------------------
这是什么题目啊,错误连天,1、getCountry()方法应该定义string 类型,2、country 不能是私有类型