How to count number of Instance of a class

public class Bicycle {
...
public static int INSTANCES = 0;
...
  //constructor
    public Bicycle(int gear, int speed, int seatHeight, String color) {
        gear = 0;
        speed = 0;
        seatHeight = 0;
        color ="Unknown";
        Bicycle.INSTANCES++;
    }

    protected void finalize() {
        INSTANCES--;
    }

}


a. System.gc();
b. Runtime.getRuntime.gc();



Comments

Popular posts from this blog

தட்டு வண்டியில் காளிக்கோயில் - சிறுகதை

பிரேமாவின் பெண் குழந்தை

தீபம் பிளக்ஸ்