🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← All topics

Quiz: Creational Patterns in Java: questions with answers

10 questions, each with the answer and a short explanation.

Take the timed quiz + get a certificate →
  1. Q1. Why is a Singleton's constructor made private?
  2. Q2. What is wrong with this lazy Singleton? static AppConfig get() { if (instance == null) instance = new AppConfig(); return instance; }
  3. Q3. In double-checked locking, why must the instance field be volatile?
  4. Q4. What does this print? (code)
  5. Q5. Which Singleton version is also protected against reflection and serialization creating a second instance?
  6. Q6. A Factory method should usually return:
  7. Q7. What does this print? (code)
  8. Q8. What problem does the Builder pattern mainly solve?
  9. Q9. Why does each Builder setter return this?
  10. Q10. Which statement about Singletons in Spring Boot applications is correct?