nerdexam
Oracle

1Z0-851 · Question #246

Given: public class NamedCounter { private final String name; private int count; public NamedCounter(String name) { this.name = name; } public String getName() { return name; } public void…

The correct answer is A. declare reset() using the synchronized keyword C. declare getCount() using the synchronized keyword E. declare increment() using the synchronized keyword. See the full explanation below for the reasoning.

Question

Given: public class NamedCounter { private final String name; private int count; public NamedCounter(String name) { this.name = name; } public String getName() { return name; } public void increment() { count++; } public int getCount() { return count; } public void reset() { count = 0; } } Which three changes should be made to adapt this class to be used safely by multiple threads? (Choose three.)

Options

  • Adeclare reset() using the synchronized keyword
  • Bdeclare getName() using the synchronized keyword
  • Cdeclare getCount() using the synchronized keyword
  • Ddeclare the constructor using the synchronized keyword
  • Edeclare increment() using the synchronized keyword

How the community answered

(32 responses)
  • A
    78% (25)
  • B
    16% (5)
  • D
    6% (2)

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice