nerdexam
Oracle

1Z0-851 · Question #220

Given: public class TestSeven extends Thread { private static int x; public synchronized void doThings() { int current = x; current++; x = current; } public void run() { doThings(); } } Which…

The correct answer is E. Declaring the doThings() method as static would make the class thread-safe. See the full explanation below for the reasoning.

Question

Given: public class TestSeven extends Thread { private static int x; public synchronized void doThings() { int current = x; current++; x = current; } public void run() { doThings(); } } Which statement is true?

Options

  • ACompilation fails.
  • BAn exception is thrown at runtime.
  • CSynchronizing the run() method would make the class thread-safe.
  • DThe data in variable "x" are protected from concurrent access problems.
  • EDeclaring the doThings() method as static would make the class thread-safe.
  • FWrapping the statements within doThings() in a synchronized(new Object()) { } block would make

How the community answered

(38 responses)
  • A
    3% (1)
  • B
    3% (1)
  • D
    11% (4)
  • E
    76% (29)
  • F
    8% (3)

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice