nerdexam
Oracle

1Z0-829 · Question #1

1Z0-829 Question #1: Real Exam Question with Answer & Explanation

Sign in or unlock 1Z0-829 to reveal the answer and full explanation for question #1. The question stem and answer options stay visible for context.

Question

Given the code fragments: class Test { volatile int x = 1; AtomicInteger xObj = new AtomicInteger(1); } and public static void main(String[] args) { Test t = new Test(); Runnable r1 = () -> { Thread trd = Thread.currentThread(); while (t.x < 3) { System.out.print(trd.getName() + ": "+t.x+" : "); t.x++; } }; Runnable r2 = () -> { Thread trd = Thread.currentThread(); while (t.xObj.get() < 3) { System.out.print(trd.getName() + ": "+t.xObj.get()+" : "); t.xObj.getAndIncrement(); } }; Thread t1 = new Thread(r1,"t1"); Thread t2 = new Thread(r2,"t2"); t1.start(); t2.start(); } Which is true?

Options

  • AThe program prints t1 : 1: t1 : 1: t1 : 2 : t2 : 2 in random order.
  • BThe program prints t1 : 1 : t2 : 1 : t1 : 2 : t2 : 2.
  • CThe program prints t1 : 1 : t1 : 1 : t2 : 1 : indefinitely
  • DThe program prints an exception

Unlock 1Z0-829 to see the answer

You've previewed enough free 1Z0-829 questions. Unlock 1Z0-829 for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.

Full 1Z0-829 Practice