Check out example codes for "java get number of class instances". It will help you in understanding the concepts better.

Code Example 1

public class Bicycle {
...
    public static int instances = 0;

    {
        ++instances; //separate counting from constructor
    }
...
    public Bicycle(int gear, int speed, int seatHeight, String color) {
        gear = 0;
        speed = 0;
        seatHeight = 0;
        color ="Unknown";
    }
}

Learn ReactJs, React Native from akashmittal.com