Java OCA OCP Practice Question 3003

Question

In the context of Singleton pattern, which one of the following statements is true?

  • a) a Singleton class must not have any static members
  • b) a Singleton class has a public constructor
  • c) a Factory class may use Singleton pattern
  • d) all methods of the Singleton class must be private


c)

Note

a Factory class generates the desired type of objects on demand.

hence, it might be required that only one Factory object exists; in this case, Singleton can be employed in a Factory class.

a) a Singleton class needs to have a static member to return a singleton instance

b) a Singleton class must declare its constructor(s) private to ensure that they are not instantiated

d) a static method (typically named getInstance()) with public access may need to be provided to get the instance of the Singleton class.




PreviousNext

Related