SCJP 1.6版考題 137

出自 陳富國維基館
於 2013年3月30日 (六) 03:23 由 Ikk (對話 | 貢獻) 所做的修訂 (新頁面: Given: 11. class X{public void foo(){System.out.print("X ");}} 12. 13. public class SubB extends X{ 14. public void foo() throws RuntimeException{ 15. uper.foo(); 16. if(t...)
(差異) ←上個修訂 | 最新修訂 (差異) | 下個修訂→ (差異)
前往: 導覽搜尋
Given:
11. class X{public void foo(){System.out.print("X ");}}
12.
13. public class SubB extends X{
14.   public void foo() throws RuntimeException{
15.   uper.foo();
16.   if(true) throw new RuntimeException();
17.   System.out.print("B ");
18. }
19.   public static void main(String[] args){
20.     new SubB().foo();
21.   }
22. }
 

What is the result?
 A. X, followed by an Exception.
 B. No output, and an Exception is thrown.
 C. Compilation fails due to an error on line 14.
 D. Compilation fails due to an error on line 16.
 E. Compilation fails due to an error on line 17.
 F. X, followed by an Exception, followed by B.

解答


Ans: A

解說: 叫用super.foo()印出X,16行丟出RuntimeException,沒有catch,main也沒有catch,所以整個程式發生例外結束。