public class Bicycle {
private int cadence;
private int gear;
private int speed;
private int id;
private static int numberOfBicycles = 0;
public Bicycle(int startCadence, int startSpeed, int startGear){
gear = startGear;
cadence = startCadence;
speed = startSpeed;
id = ++numberOfBicycles;
}
// ...
}
I learned in my class that Static variables should be accessed by calling with class name
. i.e. ClassName.VariableName
But in the code above, how is this statement id = ++numberOfBicycles;
compiled without errors, even though the variable numberOfBicycles
is static