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

多项选择题

public class TestFive { 
private int x; 
public void foo() { 
int current = x; 
x = current + 1; 
} 
public void go() { 
for(int i=0;i<5;i++) { 
new Thread() { 
public void run() { 
foo(); 
System.out.print(x + “, “); 
} }.start(); 
}}} 
Which two changes, taken together, would guarantee the output: 1, 2, 3, 4, 5, ?()

    A. Move the line 12 print statement into the foo() method.
    B. Change line 7 to public synchronized void go() {.
    C. Change the variable declaration on line 3 to private volatile int x;.
    D. Wrap the code inside the foo() method with a synchronized( this ) block.
    E. Wrap the for loop code inside the go() method with a synchronized block synchronized(this) { // for loop code here }.

点击查看答案&解析

相关考题

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

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