Skip to main content
1 of 4
Basile Starynkevitch
  • 32.7k
  • 6
  • 87
  • 131

It is explained here :

Sometimes, you want to have variables that are common to all objects. This is accomplished with the static modifier. Fields that have the static modifier in their declaration are called static fields or class variables. They are associated with the class, rather than with any object. Every instance of the class shares a class variable, which is in one fixed location in memory. Any object can change the value of a class variable, but class variables can also be manipulated without creating an instance of the class.

A class variable (declared static) is a location common to all instances.

In the example, numberOfBicycles is a class variable. There is only one such variable (i.e. location) common to all instances and to the class.

Basile Starynkevitch
  • 32.7k
  • 6
  • 87
  • 131