Java SE 8 Programmer II — Question 39

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

Answer options

Correct answer: A, B

Explanation

Option A is correct because making the class private prevents instantiation from outside the class. Option B is also correct as overriding equals() and hashCode() ensures that the singleton instance maintains its identity in collections. Options C, D, and E do not directly contribute to enforcing the singleton nature of the class.