问题:
public class SyncTest {
private int x;
private int y;
private synchronized void setX( int i ) { x = i; }
private synchronized void setY( int i ) { y = i; }
public void setXY( int i ) { setX(i); setY(i); }
public synchronized boolean check() { return x != y; }
}
Under which condition will check return true when called from a different class? ()
A . check can never return true.
B . check can return true when setXY is called by multiple threads.
C . check can return true when multiple threads call setX and setY separately.
D . check can return true only if SyncTest is changed to allow x and y to be set separately.
public class SyncTest {
private int x;
private int y;
private synchronized void setX( int i ) { x = i; }
private synchronized void setY( int i ) { y = i; }
public void setXY( int i ) { setX(i); setY(i); }
public synchronized boolean check() { return x != y; }
}
Under which condition will check return true when called from a different class? ()
● 参考解析
本题暂无解析
相关内容
相关标签