java get number of class instances

Solutions on MaxInterview for java get number of class instances by the best coders in the world

showing results for - "java get number of class instances"
Gillian
15 Jul 2020
1public class Bicycle {
2...
3    public static int instances = 0;
4
5    {
6        ++instances; //separate counting from constructor
7    }
8...
9    public Bicycle(int gear, int speed, int seatHeight, String color) {
10        gear = 0;
11        speed = 0;
12        seatHeight = 0;
13        color ="Unknown";
14    }
15}