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


Please Help Members By Posting Answers For Below Questions

Explain hashset and its features?

809


What is sorting algorithm in java?

762


define the terminology association.

855


What is the largest long allowed by java?

756


What are some examples of variable costs?

691


Why are functions called methods in java?

735


Can we synchronize static methods in java?

775


What is the longest unicode character?

869


Why charat is used in java?

795


What happens to a static var that is defined within a method of a class?

762


What are structs in java?

777


Differences between external iteration and internal iteration?

842


What is the primitive type short?

783


What is double word?

736


What is the purpose of the enableevents() method?

775