多項(xiàng)選擇題

class Waiting implements Runnable { 
boolean flag = false; 
public synchronized void run() { 
if (flag) { 
flag = false; 
System.out.print("1 "); 
try { this.wait(); } catch (Exception e) { } 
System.out.print("2 "); 
} 
else { 
flag = true; 
System.out.print("3 "); 
try { Thread.sleep(2000); } catch (Exception e) { } 
System.out.print("4 "); 
notify(); 
} 
} 
public static void main(String [] args) { 
Waiting w = new Waiting(); 
new Thread(w).start(); 
new Thread(w).start (); 
} 
} 
以下哪兩項(xiàng)是正確的?() 

A.代碼輸出 1 3 4
B.代碼輸出 3 4 1
C.代碼輸出 1 2 3 4
D.代碼不會(huì)完成

微信掃碼免費(fèi)搜題