Which two statements enforce the singleton nature of th…

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

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

A.
Make the class static.

B.
Make the constructor private.

C.
Override equals() and hashCode() methods of the java.lang.Object class.

D.
Use a static reference to point to the single instance.

E.
Implement the Serializable interface.



Leave a Reply 2

Your email address will not be published. Required fields are marked *


andrei

andrei

B, D
Generaly, there are two ways to implement a Singleton:
1) With a private constructor and a static factory method
2) As an enum