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();
答案:DF
參考:8-5-4 匿名內部類別、13-2 Java執行緒與Thread類別、13-3 Runnable介面
沒有留言:
張貼留言