Sunday, May 25, 2014

write a program so that whenever you create a object, you will get to know how many object u have created.

public class ObjectCount {
    static int numOfObj;
    ObjectCount(){
        numOfObj = numOfObj+1;
        System.out.println("Total Number of object created: "+numOfObj);
    }
    public static void main(String[] args) {
        ObjectCount obj1 = new ObjectCount();
        ObjectCount obj2 = new ObjectCount();
        ObjectCount obj3 = new ObjectCount();
    }
}

No comments:

Post a Comment