Java Singleton Pattern

  • + 0 comments

    Here is my solution, have a look into it

    class Singleton{
    
       //create an object of Singleton
       private static Singleton instance = new Singleton();
       public String str;
       //make the constructor private so that this class cannot be
       //instantiated
       private Singleton(){}
    
       //Get the only object available
       public static Singleton getSingleInstance(){
          return instance;
       }
    }