Fields
Fields are variables on the class level. They represent the state of an object. They are variables, with defined type and possible initial value. Fields can be static, final, transient, and volatile, and the access may be modified with the public, protected, and private keywords.
Static fields belong to the class. It means that there is one of them shared by all the instances of the class. Normal, non-static fields belong to the objects. If you have a field named f, then each instance of the class has its own f. If f is declared static, then the instances will share the very same f field.
The final fields cannot be modified after they are initialized. Initialization can be done on the line where they are declared, in an initializer ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access