Originally posted by Nousheed Mohammed:
The object will be created once in static method and if someone calls this static method more than once, object reference will be returned... it is called singleton class
Howdy Nousheed Mohammed,
Welcome to JavaRanch
Thanks for the contributions.
Henry was intended to point out a flaw in the code (even when you say, a Singleton class). The main intention is to restrict the total number of objects being created for the class is one and only one under any circumstances.
The way you have written the getInstance() method would fit in for just a demonstration but is not foolproof. Just to give you a clue,
you may have to "protect" method in such a way that no two accesses to the method happen simultaneously (at the same time). So, your method needs some improvements!