Wrong answer in Mock test 804 - latest version
Posted: Wed Jul 13, 2016 11:27 am
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.
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.