Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 114

Which two are elements of a singleton class? (Choose two.)

    Correct Answer: C, D

    A singleton class typically includes a private constructor to prevent direct instantiation (so that only one instance of the class can be created) and a public static method that returns the sole instance of the class. The private constructor ensures that no other instances can be created except through the class itself, and the public static method provides a global point of access to the instance.

Discussion
JME_CHGOptions: CD

C,D, not B otherwise could keep calling that public method and instantiate multiple times

WilsonKKerllOptions: CD

public class SingletonGreed { private static SingletonGreed instance = new SingletonGreed(); private SingletonGreed(){} public static SingletonGreed getInstance () { return instance; } }

Svetleto13Options: CD

C,D checked.

lchowenOptions: CD

Considering the standard Singleton implementation (i.e. the Bill Pugh implementation) : public class BillPughSingleton { private BillPughSingleton(){} private static class SingletonHelper{ private static final BillPughSingleton INSTANCE = new BillPughSingleton(); } public static BillPughSingleton getInstance(){ return SingletonHelper.INSTANCE; } } We can conclude that answer is CD

kartaOptions: CD

anser is C D

steefaandOptions: CD

C and D are correct since we need static method to return instance of singleton and private constructor so that it is not possible to create multiple instances.

OhayouOptions: CD

Answer : CD

mevltOptions: BD

it is BD because constructor has to be private to prevent instantiation and also there must be a method to check if there is already an object of it to provide otherwise create a new one.

petetsaiOptions: DE

D E~~~!!!