🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.A public constructor and a static field
  2. B.An enum with one constant, like enum Config { INSTANCE; }
  3. C.An abstract class
  4. 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 →