Exit 1Z0-830 Java SE 21 Developer Professional
Question 1 of 5
0% complete
Q1 Single choice

Given:

java

public class Test {

static int count;

synchronized Test() {

count++;

}

public static void main(String[] args) throws InterruptedException {

Runnable task = Test::new;

Thread t1 = new Thread(task);

Thread t2 = new Thread(task);

t1.start();

t2.start();

t1.join();

t2.join();

System.out.println(count);

}

}

What is the given program's output?

  • A

    It's either 1 or 2

  • B

    It's either 0 or 1

  • C

    It's always 2

  • D

    It's always 1

  • E

    Compilation fails

Previous Next