Which two statements are true? (Choose two.)

Given:

public class PingPong implements Runnable {
synchronized void hit(long n) {
for (int i = 1; i < 3; i++)
System.out.print(n + “-” + i + ” “);
}

public static void main(String[] args) {
new Thread(new PingPong()).start();
new Thread(new PingPong()).start();
}

public void run() {
hit(Thread.currentThread().getId());
}
}

Which two statements are true? (Choose two.)

Given:

public class PingPong implements Runnable {
synchronized void hit(long n) {
for (int i = 1; i < 3; i++)
System.out.print(n + “-” + i + ” “);
}

public static void main(String[] args) {
new Thread(new PingPong()).start();
new Thread(new PingPong()).start();
}

public void run() {
hit(Thread.currentThread().getId());
}
}

Which two statements are true? (Choose two.)

A.
The output could be 8-1 7-2 8-2 7-1

B.
The output could be 7-1 7-2 8-1 6-1

C.
The output could be 8-1 7-1 7-2 8-2

D.
The output could be 8-1 8-2 7-1 7-2

Explanation:



Leave a Reply 1

Your email address will not be published. Required fields are marked *