← 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?
- A.To make the field private
- B.So another thread cannot see a reference to a partly constructed object
- C.So the object can be garbage collected
- 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 →