Free Data Structures and Algorithms Course









Subscribe below and get all best seller courses for free !!!










OR



Subscribe to all free courses

How to implement Singleton Design Pattern in java with a simple program ?

Program to implement Singleton Design Pattern in java with a simple program

package com.hubberspot.singleton;

public class Singleton {

   private static Singleton singleInstance;
  
   private Singleton() {}
 
   public static synchronized Singleton getInstance() {
      if (singleInstance == null) {
   singleInstance = new Singleton();
      }
      return singleInstance;
   }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        throw new CloneNotSupportedException();
    }
  
}





 
© 2021 Learn Java by Examples Template by Hubberspot