Lavanya, regarding question 1, I think the answer is B.
I did some modifications and some
testing code, it is not too elegant, but it may help. Check this out:
import static java.lang.System.*;
class TestThread extends Thread {
private TestClass t;
private int milliseconds;
private int setIto;
TestThread(TestClass t, int setIto, int milliseconds){
this.t = t;
this.milliseconds = milliseconds;
this.setIto = setIto;
}
public void run(){
t.setXY(setIto, milliseconds);
}
}
public class TestClass {
private int x;
private int y;
public static void main (
String[] argv) {
TestClass tc = new TestClass();
TestThread tt1 = new TestThread(tc, 5, 50000);
TestThread tt2 = new TestThread(tc, 6, 0);
tt1.start();
tt2.start();
try {
tt2.join();
} catch (Exception ex){}
out.println(tc.check());
}
private synchronized void setX( int i ) { x = i; }
private synchronized void setY( int i ) { y = i; }
public void setXY(int i, int milliseconds) {
setX(i);
try {
Thread.sleep(milliseconds);
} catch (Exception unused) {}
setY(i);
}
public synchronized boolean check() { return x != y; }
}
Hope it helps
Marx
[ April 18, 2006: Message edited by: Marx Villegas ]