Choose Your Language

Thursday, 4 April 2013

Object Counter Program

public class ObjectCounter {
    static int count;
   public ObjectCounter(){
        count++;
       
    }
    public static void main(String a[]){
        ObjectCounter oc1=new ObjectCounter();
        ObjectCounter oc2=new ObjectCounter();
        System.out.println("Number of objects created is "+count);
    }
}

Output
run:
Number of objects created is 2
BUILD SUCCESSFUL (total time: 1 second)

No comments:

Post a Comment