Skip to content
Sharp

Core Java · interview question

In Java, how can you ensure that a class has only one instance?

Multiple choiceMediumchapter-2-curatedpremiumcore-javacode-reading-and-refactoring-to-objects
Choose one answer
Answer and explanation

Correct answer

B. Implement the Singleton pattern.

Why

The Singleton pattern ensures that a class has only one instance by controlling the instance creation process. By keeping the constructor private and providing a static method to get the instance, you enforce a single, shared instance.

Test yourself on Core Java

A free test with instant, explained results. No account needed.

Start free test
All Core Java questions →