7.11 Static Class Members
As we have mentioned, a separate set of instance variables is created for each object that is instantiated. In addition to instance variables, classes can define class variables, which are created only once, when the JVM initializes the class. Thus, class variables exist before any objects are instantiated, and each class has only one copy of its class variables.
You can designate a class variable by using the keyword static in its definition. Also, static variables that are constants are usually declared to be public because they typically are provided to make it easier to use the class. For example, the PI and E static constants in the Math class are provided so that our applications do not need to define those ...
Get Java Illuminated, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.