Given:                        
1. public class SyncTest {                       
2. private int x;                       
3. private int y;                       
4. private synchronized void setX( int i ) { x = i; }                       
5. private synchronized void setY( int i ) { y = i; }                   
6. public void setXY( int i ) { setX(i); setY(i); }                   
7. public synchronized boolean check() { return x != y; }                   
8. }                   
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.                   
      本人在B和C之间犹豫。

 posted on 2011-03-02 22:24  SunnyYue  阅读(175)  评论(0编辑  收藏  举报