可学答题网 > 问答 > SCJP程序员认证考试题库
目录: 标题| 题干| 答案| 搜索| 相关
问题

public class SyncTest 


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.
参考答案
参考解析:
分类:SCJP程序员认证考试题库
相关推荐

1、10. public class Class

10. public class ClassA { 11. public void methodA() { 12. ClassB classB = new ClassB()...

2、public class X { 

public class X { public static void main(String [] args) { try { badMethod(); System.out.p...

3、10. public class Class

10. public class ClassA { 11. public void count(int i) { 12. count(++i); 13. } 14.&en...

4、public class SyncTest 

public class SyncTest ( private int x; private int y; private synchronized void setX (int&e...

5、public class SyncTest 

public class SyncTest (  private int x;  private int y;  private synchronized void&ensp...

6、public class X { 

public class X { public static void main (String[] args)  { byte b = 127; byte&ens...