static Variables

Recall from Section 3.2 that each object of a class maintains its own copy of every instance variable of the class. There are variables for which each object of a class does not need its own separate copy (as you’ll see momentarily). Such variables are declared static and are also known as class variables. When objects of a class containing static variables are created, all the objects of that class share one copy of those variables. Together a class’s static variables and instance variables are known as its fields. You’ll learn more about static fields in Section 8.11.

Get Java™ How To Program (Early Objects), Tenth 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.