exam questions

Exam 1z0-809 All Questions

View all questions & answers for the 1z0-809 exam

Exam 1z0-809 topic 1 question 21 discussion

Actual exam question from Oracle's 1z0-809
Question #: 21
Topic #: 1
[All 1z0-809 Questions]

Given the code fragments:
class MyThread implements Runnable {
private static AtomicInteger count = new AtomicInteger (0);
public void run () {
int x = count.incrementAndGet();
System.out.print (x+" ");
}
}
and
Thread thread1 = new Thread(new MyThread());
Thread thread2 = new Thread(new MyThread());
Thread thread3 = new Thread(new MyThread());
Thread [] ta = {thread1, thread2, thread3};
for (int x= 0; x < 3; x++) {
ta[x].start();
}
Which statement is true?

  • A. The program prints 1 2 3 and the order is unpredictable.
  • B. The program prints 1 2 3.
  • C. The program prints 1 1 1.
  • D. A compilation error occurs.
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
thetech
Highly Voted 4 years, 8 months ago
A is correct answer. Tested.
upvoted 12 times
...
asdfjhfgjuaDCV
Most Recent 4 months, 4 weeks ago
A is the correct answer: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter GDP: "); int GDP = Integer.parseInt(br.readLine()); System.out.println("GDP entered: " + GDP); } }
upvoted 1 times
asdfjhfgjuaDCV
4 months, 4 weeks ago
Its for other question
upvoted 1 times
...
...
asdfjhfgjuaDCV
4 months, 4 weeks ago
A is the correct answer. import java.util.concurrent.atomic.AtomicInteger; class MyThread implements Runnable { private static AtomicInteger count = new AtomicInteger(0); public void run() { int x = count.incrementAndGet(); System.out.print(x + " "); } } public class Main { public static void main(String[] args) { Thread thread1 = new Thread(new MyThread()); Thread thread2 = new Thread(new MyThread()); Thread thread3 = new Thread(new MyThread()); Thread[] ta = { thread1, thread2, thread3 }; for (int x = 0; x < 3; x++) { ta[x].start(); } } }
upvoted 1 times
...
steefaand
5 months, 4 weeks ago
Selected Answer: A
A is correct.
upvoted 1 times
...
r1muka5
1 year, 5 months ago
Correct answer is A.
upvoted 1 times
...
WilsonKKerll
2 years, 4 months ago
Answer is A
upvoted 1 times
...
sansay61
3 years, 7 months ago
a is correct. there's no sync block or method in runnable.
upvoted 2 times
...
Innovation
4 years, 6 months ago
A is correct, tested
upvoted 3 times
...
Ritesh_
4 years, 9 months ago
B is correct answer
upvoted 1 times
Samps
3 years, 11 months ago
try running same code several times
upvoted 2 times
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago