Java - Class Variable (Static Fields)

Java Conceptuel Diagram

About

A class variable is any field declared with the modifier static.

When the value of a static variable changes in any instance it affects the value for all instances.

Example

Number of gears for a particular kind of bicycle

A field defining the number of gears for a particular kind of bicycle could be marked as static since conceptually the same number of gears will apply to all instances.

constant named PI

For example, the following variable declaration defines a constant named PI, whose value is an approximation of pi (the ratio of the circumference of a circle to its diameter):

static final double PI = 3.141592653589793;

Constants defined in this way cannot be reassigned, and it is a compile-time error if your program tries to do so. By convention, the names of constant values are spelled in uppercase letters. If the name is composed of more than one word, the words are separated by an underscore (_).





Discover More
Java Conceptuel Diagram
Java - Constant

The names of constant fields are in upper-case letters. By convention, the names of constant values are spelled in uppercase letters. If the name is composed of more than one word, the words are separated...
Java Conceptuel Diagram
Java - Static Modifier

in Java. The Java programming language supports static methods. Static methods, which have the static modifier in their declarations, should be invoked with the class name, without the need for...



Share this page:
Follow us:
Task Runner