Java SE 8 Programmer II — Question 188

You want to create a singleton class by using the Singleton design pattern.
Which two statements enforce the singleton nature of the design? (Choose two.)

Answer options

Correct answer: B, F

Explanation

Making the constructor private (option B) prevents external instantiation, ensuring only one instance can be created within the class itself. Declaring the single instance as static and final (option F) ensures that it remains constant and is associated with the class rather than any object instance, maintaining the singleton property. The other options do not enforce the singleton nature effectively.