SCJP題庫第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.
Ans: B
解說:
17~19的run覆蓋掉定義在12~14的run方法,執行緒被啟動後(start),會跳至run方法來執行。
Comments