Page 1 of 1

Wrong answer in Mock test 804 - latest version

Posted: Wed Jul 13, 2016 11:27 am
by toandang
public class Test extends Thread {

static int x, y;

public static synchronized void setX(int i) {
x++;
}

public static synchronized void setY(int j) {
y++;
}

public void setXY(int i, int j) {
setX(i);
setY(j);
}

public boolean testXY() {
return x != y;
}

public void run() {
setXY(1, 2);
System.out.println(testXY());
}

public static void main(String[] args) {
new Test().start();
new Test().start();
}
}
The above code will always print
false
false
select 1 option:
True
False

I have tested the class, it always return false/false, correct answer is True, but the answer is false.

Re: Wrong answer in Mock test 804 - latest version

Posted: Wed Jul 13, 2016 11:58 am
by admin
Did you read the explanation given with the question?
Also, please include the question id in the subject so that we can track the question. I believe you are talking about question 2.1341, right?
-Paul.