Oracle Java SE 21 Developer Professional 1z0-830 Question # 1 Topic 1 Discussion

Oracle Java SE 21 Developer Professional 1z0-830 Question # 1 Topic 1 Discussion

1z0-830 Exam Topic 1 Question 1 Discussion:
Question #: 1
Topic #: 1

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


Get Premium 1z0-830 Questions

Contribute your Thoughts:


Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.