2009年2月26日 星期四

第231題

Given:
11. Runnable r = new Runnable(){
12. public void run(){
13. System.out.print("Cat");
14. }
15. };
16. Thread t = new Thread(r){
17. public void run(){
18. System.outprint("Dog");
19. }
20. };
21. t.start();
What is the result?
A. Cat
B. Dog
C. Compilation fails.
D. The code runs with no output.
E. An exception is thrown at runtime.
答案:B
參考:8-5-4 匿名內部類別、13-2 Java執行緒與Thread類別、13-3 Runnable介面

--------------------------------

17行改寫了12行.

沒有留言:

張貼留言