Java SE 8 Programmer II — Question 132
Which two are elements of a singleton class? (Choose two.)
Answer options
- A. a transient reference to point to the single instance
- B. a public method to instantiate the single instance
- C. a public static method to return a copy of the singleton reference
- D. a private constructor to the class
- E. a public reference to point to the single instance
Correct answer: C, D
Explanation
The correct answers are C and D. A singleton class must have a private constructor to prevent external instantiation (D), and it typically includes a public static method to return the single instance (C). Options A, B, and E are incorrect as they do not align with the singleton design pattern's requirements.