ODNYX.
Tutorials
Java
CSS
Database
DevOps
Spring
Design Patterns
References
Subscribe
Java
CSS
Database
DevOps
Spring
Design Patterns
Singleton Pattern — Quick Check
1. What does the Singleton pattern guarantee?
A class can have unlimited instances
A class has exactly one instance for the application's lifetime
A class cannot be instantiated at all
Every method in the class is static
2. Why is the Singleton's constructor marked private?
To improve performance
To prevent other code from creating additional instances directly
Private constructors are required by Java syntax
To allow subclassing
3. What's the risk with the basic (non-synchronized) getInstance() implementation?
It's slower than creating a new object every time
Two threads could both see instance == null and create two separate objects
It leaks memory over time
It only works for the first caller
Check answers
❮ Home
Next: Creational Patterns Interview Questions ❯