1. public class SyncTest ( 2. private int x; 3. private int y; 4. private synchronized void setX (int i) {x=1;}; 5. private synchronized void setY (int i) {y=1;} 6. public void setXY(int i){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. It's answer is B why not C? [Code edited by Val] [ August 21, 2002: Message edited by: Valentin Crettaz ]
Hi HiBob, setX() and setY() are private methods, so no other classes can call them. They can be called twice in succession, but in your example, only setXY() can call those methods.