欢迎来到易学考试网 易学考试官网
全部科目 > Java认证考试 > SCJP程序员认证考试

单项选择题

class Computation extends Thread { 
private int num; 
private boolean isComplete; 
private int result; 
public Computation(int num) { this.num = num; } 
public synchronized void run() { 
result = num * 2; 
isComplete = true; 
notify(); 
} 
public synchronized int getResult() { 
while (!isComplete) { 
try { 
wait(); 
} catch (InterruptedException e) { } 
} 
return result; 
} 
public static void main(String[] args) { 
Computation[] computations = new Computation [4]; 
for (int i = 0; i < computations.length; i++) { 
computations[i] = new Computation(i); 
computations[i] .start(); 
} 
for (Computation c : computations) 
System.out.print(c.getResult() +“ “); 
} 
} 
What is the result?() 

    A. The code will deadlock.
    B. The code may run with no output.
    C. An exception is thrown at runtime.
    D. The code may run with output “0 6”.
    E. The code may run with output “2 0 6 4‟.
    F. The code may ruin with output “0 2 4 6”.

点击查看答案&解析

相关考题

微信小程序免费搜题
微信扫一扫,加关注免费搜题

微信扫一扫,加关注免费搜题