Interview Q&A / Object-Oriented Programming

INTERVIEW Q&A · 69 QUESTIONS

Object-Oriented Programming interview questions

The four pillars, interfaces, abstract classes and design basics.

  1. How do you make a Singleton thread-safe in Java?

    Use eager initialisation, the holder class idiom, or an enum. If you need lazy creation with double-checked locking, the field must be volatile.

    IntermediateQuick answer1 min read
  2. Why do many developers call Singleton an anti-pattern?

    It is global state in disguise: hidden dependencies, hard-to-reset state between tests, tight coupling to one concrete class, and trouble when you later need two instances.

    IntermediateQuick answer1 min read