How many objects are created for a singleton class
Answers were Sorted based on User's Feedback
Answer / rajani nagandla
The Singleton is a useful Design Pattern for allowing only
one instance of your class.The Singleton's purpose is to
control object creation, limiting the number to one but
allowing the flexibility to create more objects if the
situation changes. Since there is only one Singleton
instance, any instance fields of a Singleton will occur
only once per class, just like static fields.
| Is This Answer Correct ? | 7 Yes | 1 No |
Singleton class allows to create only one instance of the
class. But the other objects can inherit from it. Singleton
is a Design Pattern to restrict create more than one
instance of a class.
And
1. It ensures only one object created for a class
2. Provides global point of access.
Mostly it is used to create DB connections.
| Is This Answer Correct ? | 4 Yes | 1 No |
Answer / utkarsh verma
Some correction required in last solution
void main(){
Single *ptr = Single::Instance(); //The only way to
//instantiate
}
| Is This Answer Correct ? | 3 Yes | 0 No |
Answer / chaman
Is a design pattern that is used to restrict instantiation
of a class to one object.
| Is This Answer Correct ? | 3 Yes | 1 No |
Answer / suresh solomon
in clustered environment singletons will have as many instances as JVMs
| Is This Answer Correct ? | 4 Yes | 2 No |
Answer / utkarsh verma
c++ program to explain Singleton
class Single {
private:
Single(){} //Can't instantiate
public:
Static Single* Obj;
Static *Single Instance ()
{
if(Obj == NULL)
Obj = new Single();
return Obj;
}
}//End of class
Single * Single ::Obj = NULL;
void main(){
Single *ptr = Obj->Instance(); //The only way to instantiate
}
| Is This Answer Correct ? | 3 Yes | 1 No |
What is module in project?
where to use join method and explain with real time senario?and programatical explenation also..
What are runtime exceptions?
What is the default value of byte datatype in java?
explain the classification of exception and hoew to handle the exceptions
What is the buffer limit?
In collection sorting comparable and comparator interface will be used..but why this two interfaces required..two will work same purpose so why there are two interfaces instead of one?when to use comparator and when to use comparable?
what is AWT
What is casting?
Why can't you declare a class as protected?
What is use of set in java?
When you Click a Button, What event will be fired?