Interview questions
Question 222 of 253
FreeWhat is the Singleton pattern and how do you implement it thread-safely?
Design Patterns
Singleton ensures a class has exactly one instance and provides a global access point to it. A thread-safe lazy implementation uses double-checked locking with a volatile field, or (the simplest, safest modern approach) an enum with a single constant, which the JVM guarantees is instantiated exactly once even under reflection or serialization attacks.
Intermediate5 min

