title: Singleton is Violated or Not?
body: <p>While we are creating a class using Singleton Pattern I am able to clone in the same class.
  It means the Singleton Pattern rule was violated. Can any one please clarify my doubt.
  My Code is:</p>
  
  <pre><code>class SingletonObject implements Cloneable
  {
      private SingletonObject()
      {
          // no code req'd
      }
  
      public static SingletonObject getSingletonObject()
      {
          SingletonObject obj = null;
        if (ref == null){
            // it's ok, we can call this constructor
            ref = new SingletonObject();  
  
            try {
                obj = (SingletonObject)ref.clone();
              if(obj.equals(ref)){
                  System.out.println("both objects are same");
              }else{
                  System.out.println("both objects are not same");
              }
          } catch (CloneNotSupportedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
        }    
        return obj;
      }
  
      private static SingletonObject ref;
  }
  </code></pre>