/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package patternjavaimplementation;

public class Q1 {

    private static Q1 instanceObj;
    private static int counter;

    private Q1() {
        counter = 1; 
    }

    public static synchronized Q1 getInstance() {
        if (instanceObj == null) // Lazy instantiation
        {
            instanceObj = new Q1();
        }
        return instanceObj;
    }

    public static synchronized int getNext() {
        return ++counter;
    }
}
class Test{
    public static void main(String[] args) {

        for (int i = 1; i <= 15; i++) {
            Q1 qObjects=Q1.getInstance();
            System.out.println("Object key: "+Q1.getNext()+", ");
            Q1 q=Q1.getInstance();
        }
    }
}