SCJP題庫第238題

 
Which two code fragments will execute the method doStuff() in a separate thread?
(Choose two.)
A. new Thread(){
          public void run(){doStuff();}
    };
B. new Thread(){
         public void start(){doStuff();}
    };
C new Thread(){
        public void start(){doStuff();}
    }.run();
D. new Thread(){
         public void run(){doStuff();}
    }.start();
E. new Thread(new Runnable(){
         public void run(){doStuff();}
    }).run();
F. new Thread(new Runnable(){
         public void run(){doStuff();}
    }).start();



Ans: DF

解說:題目要求那二個程式片段可以在一個分開的執行緒上執行doStuff方法。


執行緒的啟動是要呼叫start方法,若是以呼叫run來看,run方法是執行在main執行緒之上,不是分開的執行緒。

Comments

Popular posts from this blog

Android-使用webview在V3版的Google地圖GPS定位