🎙 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 2 of 10

What is wrong with this lazy Singleton? static AppConfig get() { if (instance == null) instance = new AppConfig(); retu…

What is wrong with this lazy Singleton? static AppConfig get() { if (instance == null) instance = new AppConfig(); return instance; }

  1. A.It never creates the object
  2. B.It creates the object at class-loading time
  3. C.Two threads can both see null at the same time and create two objects
  4. D.Static methods cannot return objects
Answer & explanation

Correct answer: Two threads can both see null at the same time and create two objects

Without synchronization the check and the creation are not atomic.

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 →