Skip to content
CodeKruPro

Which singletons are thread-safe?

QuizMediumJava onlyAsked in: TCS

Lazy means the object is created on first use; eager means it is created when the class loads. Which lazy or eager singleton versions are thread-safe? Pick all that apply.

  • private static final Config INSTANCE = new Config(); (eager)
  • if (instance == null) instance = new Config(); in getInstance(), with no synchronisation
  • Double-checked locking with a volatile instance field
  • enum Config { INSTANCE; }

This question is part of Pro+

Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.

See Pro+

Already have Pro+? Sign in