public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { // Singleton obj1 = new Singleton(); - compiler error as constr is private and cannot be used // from outside class Singleton5 obj1 = Singleton5.getInstance(); Singleton5 obj2 = Singleton5.getInstance(); printme("obj1", obj1); // obj1, 2018699554 printme("obj2", obj2); // obj2, 2018699554 System.out.println(obj1.equals(obj2)); // true }
public static void printme(String name, Singleton5 obj) { System.out.println(name + ", " + obj.hashCode()); }