1 /**
   2  * SingletonPattern Example
   3  */
   4 
   5 class Singleton {
   6     private static Singleton singleton = new Singleton();
   7     private Singleton() {
   8         System.out.println("Instance are made");
   9     }
  10     public static Singleton getInstance() {
  11         return singleton;
  12     }
  13 }
  14 
  15 public class SingletonEx {
  16     public static void main(String[] args) {
  17         System.out.println("Start.");
  18         Singleton obj1 = Singleton.getInstance();
  19         Singleton obj2 = Singleton.getInstance();
  20         if(obj1 == obj2) {
  21             System.out.println("obj1 == obj2");
  22         } else {
  23             System.out.println("obj1 != obj2");
  24         }
  25         System.out.println("End.");
  26     }
  27 }
web biohackers.net