1.public class SyncTest {
2.private int x;
3.private int y;
4.public synchronized void setX (int i) ( x=1; )
5.public synchronized void setY (int i) ( y=1; )
6.public synchronized void setXY(int 1)( set X(i); setY(i); )
7.public synchronized Boolean check() ( return x !=y; )
8.)
Under which conditions 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 only return true if SyncTest is changed to allow x and y to be set separately.
The given answer is B. But I am not sure that's the right answer. And I don't know what is the point of this question. What does it try to
test?
Thank you in advance.
(Marilyn disabled smilies)
[ May 05, 2002: Message edited by: Marilyn deQueiroz ]