Heading

Wednesday, October 23, 2013

Singleton Example in java


public class Singleton {

    /**
     * @param args
     */
    private  static Singleton instance;
    private Singleton()
    {
       
    }
    public static Singleton createInstance()
    {
        if(instance==null)
        {
            instance=new Singleton();
        }
        return instance;
    }
    public static void main(String[] args) {
       
// TODO Auto-generated method stub
Singleton s1=Singleton.createInstance();
Singleton s2=Singleton.createInstance();
Singleton s3=Singleton.createInstance();
System.out.println(s1+ " "+s2+" "+s3);
    }

}

No comments:

Post a Comment