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