← 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; }
- A.It never creates the object
- B.It creates the object at class-loading time
- C.Two threads can both see null at the same time and create two objects
- 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 →