|
|
行 1: |
行 1: |
− | <span style="font-size:medium;"><span style="font-family: 'Helvetica Neue Light', HelveticaNeue-Light, 'Helvetica Neue', Helvetica, Arial, sans-serif; text-align: justify;">
| |
− |
| |
− | Given:
| |
− | </span></span>
| |
− |
| |
− | <span style="font-size:medium;"><span style="font-family: 'Helvetica Neue Light', HelveticaNeue-Light, 'Helvetica Neue', Helvetica, Arial, sans-serif; line-height: 19px; text-align: justify;">
| |
− | 1. public class Threads4{
| |
− | 2. public static void main(String[] args){
| |
− | 3. new Threads4.go();
| |
− | 4. }
| |
− | 5. public void go(){
| |
− | 6. Runnable r = new Runnable(){
| |
− | 7. public void run(){
| |
− | 8. System.out.print("foo");
| |
− | 9. }
| |
− | 10. };
| |
− | 11. Thread t = new Thread(r);
| |
− | 12. t.start();
| |
− | 13. t.start();
| |
− | 14. }
| |
− | 15.}
| |
− | What is the result?
| |
− | A. Compilation fails.
| |
− | B. An exception is thrown at runtime.
| |
− | C. The code executes normally and prints "foo";
| |
− | D. The code executes normally, but nothing is printed.
| |
− |
| |
− | </span></span>
| |
− |
| |
− |
| |
− |
| |
− |
| |
− |
| |
− | <div class="toccolours mw-collapsible mw-collapsed">
| |
− | <span style="font-size:medium;">解答</span>
| |
− |
| |
− | ----
| |
− | <div class="mw-collapsible-content">
| |
− | <span style="font-size: medium;">Ans: E </span>
| |
− |
| |
− | <span style="font-size:medium;"> 解說:
| |
− | 一個執行緒只能啟動一次 (t.start()只能下一次),執行緒是物件,物件相關的動作發生問題是在執行時期產生例外,而不是編譯的錯誤。
| |
− |
| |
− | </span>
| |
− | </div></div>
| |
| {{SCJP 1.6版考題講解}} | | {{SCJP 1.6版考題講解}} |