How many objects are created for a singleton class
Answer Posted / 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 |
Post New Answer View All Answers
hr interview how many minutes asking question
What is independent and dependent variables in research?
Which types of exceptions are caught at compile time?
What is the difference between equals() and == in java?
What is the old name of java?
How do you use substring in java?
What are the methods of object class ?
Can array grow dynamically in java?
What is an object in java and how is it created?
What if the main() method is declared as private? What happens when the static modifier is removed from the signature of the main() method?
Does java support multiple inheritances?
What are exceptions
Java Compiler is stored in JDK, JRE or JVM?
What is a treeset class?
What happens if a constructor is declared private?