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.)
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 public reference to point to the single instance.
E.
Implement the Serializable interface.
F.
Make the single instance created static and final.
B. Make the constructor private.
Explanation: To ensure that a Singleton class has only one instance, its constructor should be private. This prevents anyone from creating new instances of the class from outside.
F. Make the single instance created static and final.
Explanation: To ensure that there is only one instance of a Singleton class, that instance should be declared as static and final. static means that the instance is shared by all objects of the class, and final means that it cannot be changed after it is created.
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
6c84cb9
4 months ago6c84cb9
5 months, 1 week agoasdfjhfgjuaDCV
10 months, 1 week agosteefaand
11 months, 2 weeks agoKim514
1 year, 9 months agor1muka5
1 year, 10 months agoWilsonKKerll
2 years, 9 months agoWilsonKKerll
2 years, 10 months agosamtash1034
3 years agoAVB22
3 years, 2 months ago