🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Creational Patterns in Java: all 10 questions

Quiz: Creational Patterns in Java · Question 3 of 10

In double-checked locking, why must the instance field be volatile?

In double-checked locking, why must the instance field be volatile?

  1. A.To make the field private
  2. B.So another thread cannot see a reference to a partly constructed object
  3. C.So the object can be garbage collected
  4. D.It does not need to be volatile
Answer & explanation

Correct answer: So another thread cannot see a reference to a partly constructed object

volatile guarantees the fully built object is visible before the reference is published.

Can you get the rest right without peeking?

Take the timed Quiz: Creational Patterns in Java quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →