1Z0-805 · Question #50
Given: public class DataCache { private static final DataCache instance = new DataCache (); public static DataCache getInstance () { return instance; } } Which design pattern best describes the class?
The correct answer is A. Singleton. Java has several design patterns Singleton Pattern being the most commonly used. Java Singleton pattern belongs to the family of design patterns, that govern the instantiation process. Oracle 1Z0-805 Exam This design pattern proposes that at any time there can only be one…
Question
Given:
public class DataCache { private static final DataCache instance = new DataCache (); public static DataCache getInstance () { return instance; } } Which design pattern best describes the class?
Options
- ASingleton
- BDAO
- CAbstract Factory
- DComposition
How the community answered
(47 responses)- A83% (39)
- B4% (2)
- C11% (5)
- D2% (1)
Explanation
Java has several design patterns Singleton Pattern being the most commonly used. Java Singleton pattern belongs to the family of design patterns, that govern the instantiation process. Oracle 1Z0-805 Exam This design pattern proposes that at any time there can only be one instance of a singleton (object) created by the JVM. The class's default constructor is made private, which prevents the direct instantiation of the object by others (Other Classes). A static modifier is applied to the instance method that returns the object as it then makes this method a class level method that can be accessed without creating an object.
Topics
Community Discussion
No community discussion yet for this question.