🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.To make it faster
  2. B.So it can be overridden
  3. C.So two threads cannot both see instance == null and create two objects
  4. 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 →