nerdexam
Oracle

1Z0-809 · Question #40

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+"…

The correct answer is A. The program prints 1 2 3 and the order is unpredictable. You've hit your session limit · resets 5:20pm (America/New_York)

Question

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?

Options

  • AThe program prints 1 2 3 and the order is unpredictable.
  • BThe program prints 1 2 3.
  • CThe program prints 1 1 1.
  • DA compilation error occurs.

How the community answered

(54 responses)
  • A
    78% (42)
  • B
    6% (3)
  • C
    4% (2)
  • D
    13% (7)

Explanation

You've hit your session limit · resets 5:20pm (America/New_York)

Community Discussion

No community discussion yet for this question.

Full 1Z0-809 Practice