"SCJP 1.6版考題 001" 修訂間的差異

出自 陳富國維基館
前往: 導覽搜尋
(新頁面: <span style="font-size:medium;"><span style="font-family: 'Helvetica Neue Light', HelveticaNeue-Light, 'Helvetica Neue', Helvetica, Arial, sans-serif; text-align: justify;"> <BR>Give...)
 
 
(未顯示同一使用者於中間所作的 1 次修訂)
行 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;">  
 
<span style="font-size:medium;"><span style="font-family: 'Helvetica Neue Light', HelveticaNeue-Light, 'Helvetica Neue', Helvetica, Arial, sans-serif; text-align: justify;">  
 +
</span></span>
  
<BR>Given:
+
<br>Given:  
 
+
 
+
1. public class Threads4{  
<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;">
+
2. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;public static void main(String[] args){  
<BR>1. public class Threads4{
+
3. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new Threads4.go();  
<BR>2.   public static void main(String[] args){
+
4. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }  
<BR>3.     new Threads4.go();
+
5. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;public void go(){  
<BR>4.   }
+
6. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Runnable r = new Runnable(){  
<BR>5.   public void go(){
+
7. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;public void run(){  
<BR>6.     Runnable r = new Runnable(){
+
8. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  &nbsp;System.out.print("foo");
<BR>7.       public void run(){
+
9. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}  
<BR>8.         System.out.print("foo");
+
10. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;};  
<BR>9.       }
+
11. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread t = new Thread(r);  
<BR>10.   };
+
12. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.start();  
<BR>11.   Thread t = new Thread(r);
+
13. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.start();  
<BR>12.     t.start();
+
14. &nbsp; &nbsp; &nbsp; &nbsp; }  
<BR>13.     t.start();
+
15. &nbsp;}  
<BR>14. }
+
<br>  
<BR>15.}
+
What is the result?  
<BR>
+
    A. Compilation fails.  
<BR>What is the result?
+
    B. An exception is thrown at runtime.  
<BR>A. Compilation fails.
+
    C. The code executes normally and prints "foo";  
<BR>B. An exception is thrown at runtime.
+
    D. The code executes normally, but nothing is printed.
<BR>C. The code executes normally and prints "foo";
 
<BR>D. The code executes normally, but nothing is printed.
 
 
 
</span></span>
 
 
 
 
 
 
 
 
 
  
 
<div class="toccolours mw-collapsible mw-collapsed">
 
<div class="toccolours mw-collapsible mw-collapsed">

於 2013年3月30日 (六) 09:13 的最新修訂


Given: 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.

解答


Ans: E

解說: 一個執行緒只能啟動一次 (t.start()只能下一次),執行緒是物件,物件相關的動作發生問題是在執行時期產生例外,而不是編譯的錯誤。