PROGRAM TO COUNT NUMBER OF OBJECTS CREATED FOR A CLASS

//PROGRAM TO COUNT NUMBER OF OBJECTS CREATED FOR A CLASS.
public class CountObjects {
private static byte c;
CountObjects()
{
c++;
}
public void display()
{
System.out.print(c);
}
public static void main(String args[])
{
CountObjects ob1=new CountObjects();
CountObjects ob2=new CountObjects();
CountObjects ob3=new CountObjects();
CountObjects ob4=new CountObjects();
CountObjects show=new CountObjects();
show.display();
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *