Given:
11. static void test() throws RuntimeException{
12. try{
13. System.out.print("test ");
14. throw new RuntimeException();
15. }
16. catch(Exception ex){ System.out.print("exception ");}
17. }
18. public static void main(String[] args){
19. try{test();}
20. catch(RuntimeException ex){System.out.print("runtime ");}
21. System.out.print("end ");
22. }
What is the result?
A. test end
B. Compilation fails.
C. test runtime end
D. test exception end
E. A Throwable is thrown by main at runtime.
答案:D
參考:9-2 Java例外事件與處理機制
------------------------------------------------------------------------------
19. try{test();}
>>13. System.out.print("test ");
>>14. throw new RuntimeException();
>>16. catch(Exception ex){ System.out.print("exception ");}
>>21. System.out.print("end ");
沒有留言:
張貼留言