Fields

Fields are variables on the class level. They represent the state of an object. They are variables with defined a type and a 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, nonstatic 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 ...

Get Java Projects - Second 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.