A class which allow users to create only 2 objects or 2 times.
so in this we use array.
in singleton we create only once and in this we create object only twice.
Example:-
D array can contain only 2 objects because the size of D array is 2.
inside SIB we create 2 objects both are storing inside the array.
private constructor is used so nobody can create the object of the class.
in the getObject method we use return statement which returns only 0 and 1
the index of object is 0 and 1 so we can create only 2 objects and access only 2 objects due to the query written statement return only 0 and 1.
so in this we use array.
in singleton we create only once and in this we create object only twice.
Example:-
inside SIB we create 2 objects both are storing inside the array.
private constructor is used so nobody can create the object of the class.
in the getObject method we use return statement which returns only 0 and 1
the index of object is 0 and 1 so we can create only 2 objects and access only 2 objects due to the query written statement return only 0 and 1.
No comments :
Post a Comment