SCJP 1.6版考題 056

出自 陳富國維基館
於 2013年3月30日 (六) 07:10 由 Ikk (對話 | 貢獻) 所做的修訂 (新頁面: 5. class Building{} 6. public class Barn extends Building{ 7. public static void main(String[] args){ 8. Building build1 = new Building(); 9. Barn barn1 = new Barn(); 1...)
(差異) ←上個修訂 | 最新修訂 (差異) | 下個修訂→ (差異)
前往: 導覽搜尋
5. class Building{}
6. public class Barn extends Building{
7.   public static void main(String[] args){
8.     Building build1 = new Building();
9.     Barn barn1 = new Barn();
10.   Barn barn2 = (Barn)build1;
11.   Object obj1 = (Object)build1;
12.   String str1 = (String)build1;
13.   Building build2 = (Building)barn1;
14.   }
15. }


Which is true?
  A. if line 10 is removed, the compilation succeeds.
  B. if line 11 is removed, the compilation succeeds.
  C. if line 12 is removed, the compilation succeeds.
  D. if line 13 is removed, the compilation succeeds.
  E. More than one line must be removed for compilation to succeed.

解答


Ans: C

解說:

只有繼承關係可以進行casting(轉換型態)。
Build1是Building型態,和String型態沒有繼承關係