← Quiz: Design Patterns: all 10 questions
Quiz: Design Patterns · Question 6 of 10
Why is the get() method of the lesson's AppConfig Singleton marked synchronized?
Why is the get() method of the lesson's AppConfig Singleton marked synchronized?
- A.To make it faster
- B.So it can be overridden
- C.So two threads cannot both see instance == null and create two objects
- D.Because static methods must be synchronized
Answer & explanation
Correct answer: So two threads cannot both see instance == null and create two objects
Without it, a race can create two instances in multi-threaded code.
Can you get the rest right without peeking?
Take the timed Quiz: Design Patterns quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →