What does the Singleton pattern guarantee?

Get ready for your Object‑Oriented Programming Test. Use flashcards and multiple-choice questions. Each question includes hints and explanations. Prepare for your exam today!

Multiple Choice

What does the Singleton pattern guarantee?

Explanation:
A Singleton guarantees there is exactly one instance of a class and a single global way to access that instance. The pattern achieves this by letting the class control its own creation—typically with a private constructor—and exposing a public static method (often called getInstance) that always returns the same instance. Because there is only one object in the runtime, all parts of the program share that same instance through that global access point, ensuring consistent state and coordinated access. This aligns with the idea of exactly one instance in the JVM (per class loader context) plus a single global entry point to obtain it. Other options misrepresent the pattern—for example, they imply multiple instances or no central access—so they don’t fit the intended guarantee.

A Singleton guarantees there is exactly one instance of a class and a single global way to access that instance. The pattern achieves this by letting the class control its own creation—typically with a private constructor—and exposing a public static method (often called getInstance) that always returns the same instance. Because there is only one object in the runtime, all parts of the program share that same instance through that global access point, ensuring consistent state and coordinated access. This aligns with the idea of exactly one instance in the JVM (per class loader context) plus a single global entry point to obtain it. Other options misrepresent the pattern—for example, they imply multiple instances or no central access—so they don’t fit the intended guarantee.