Machine-translated by Google. Questions are authored in English.
Top

Discussion

Where the synchronized keyword may be applied - which of the following is true?

  • A.synchronized may be applied to a field, making every read and write of that field atomic and visible.
  • B.synchronized may be applied only to methods, never to a block.
  • C.synchronized may be applied to a method or to a block, but not to a class or a field.
  • D.synchronized may be applied to a class.

Answer: C

The keyword marks a method or a block; there is no synchronized class and no synchronized field. Making a field's individual reads and writes atomic and visible is what volatile does, and neither keyword makes a compound update such as an increment safe on its own.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.