Accessing Static variables

后端 未结 8 1121
清歌不尽
清歌不尽 2020-12-31 09:50
public class Bicycle {

    private int cadence;
    private int gear;
    private int speed;
    private int id;
    private static int numberOfBicycles = 0;

    p         


        
8条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-31 10:36

    Static variables are the shared variables. So you can access them using either the Classname.staticVariable or using an object of the class instance.staticVariable. In any case you will be referring to the single copy of the variable in memory, no matter how many objects you create.

提交回复
热议问题