SCJP題庫第137題

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()印出X16行丟出RuntimeException,沒有catchmain也沒有catch,所以整個程式發生例外結束。

Comments

Popular posts from this blog

Android+Google Map API v3 Geocoding(地址轉經緯度度