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

What do you understand by classes in java?

551


I want my class to be developed in such a way that no other class (even derived class) can create its objects. How can I do so?

514


How can you set an applet’s height and width as a percentage?

504


What does void * mean?

524


Hi all, I am dng a mini project on FileSplitter application which splits the GBs of logfile into Smaller chunks(mbs) depending on the split size." How to handle GBs file? I am getting OutOfMemoryException, when I input such GB sized file. Thx

1596






What is a class variable?

562


Can an interface have a class?

557


What are the advantages of arraylist over arrays?

558


Name some classes present in java.util.regex package.

598


What are the different ways to handle exceptions?

535


What is instance means in java?

559


take an array with -ve and +ve value both.find out the nearest value of 0(zero).if two values are same like(-2 and +2)then extract +2 is nearest of 0(zero).

1529


What is Major and importance difference between for and foreach loop ?

568


What is the purpose of void?

528


What is tree node in java?

524