black

Java认证考试综合练习

登录

多项选择题

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 (); 
} 
} 
以下哪两项是正确的?() 

A.代码输出 1 3 4
B.代码输出 3 4 1
C.代码输出 1 2 3 4
D.代码不会完成

相关考题

多项选择题 哪两个java.lang.Thread方法抛出受检异常?()

多项选择题 class Order implements Runnable {  public void run() {  try { Thread.sleep(2000); } catch (Exception e) { }  System.out.print("in ");  }  public static void main(String [] args) {  Thread t = new Thread(new Order());  t.start();  System.out.print("pre ");  try { t.join(); } catch (Exception e) { }  System.out.print("post ");  } }  可产生哪两项结果?()

多项选择题 下列哪些方法是Thread类中所定义的方法?()

All Rights Reserved 版权所有©计算机考试题库(jsjtiku.com)

备案号:湘ICP备14005140号-4

经营许可证号:湘B2-20140064