← Quiz: Java Enums: all 10 questions
Quiz: Java Enums · Question 10 of 10
Which is a simple, thread-safe way to write a Singleton in Java?
Which is a simple, thread-safe way to write a Singleton in Java?
- A.A public constructor and a static field
- B.An enum with one constant, like enum Config { INSTANCE; }
- C.An abstract class
- D.An interface with a default method
Answer & explanation
Correct answer: An enum with one constant, like enum Config { INSTANCE; }
The JVM creates enum constants exactly once, safely, even with many threads.
Can you get the rest right without peeking?
Take the timed Quiz: Java Enums quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →