1
Loading subject content…
Loading subject content…
Loading practice questions…
What is the output of the following program?
public class Main {
static int count = 0;
static synchronized void inc() { count++; }
public static void main(String[] args) throws InterruptedException {
Thread a = new Thread(() -> { for (int i = 0; i < 1000; i++) inc(); });
Thread b = new Thread(() -> { for (int i = 0; i < 1000; i++) inc(); });
a.start(); b.start();
a.join(); b.join();
System.out.println(count);
}
}