Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: added xref

...

The final keyword in Java is used to declare constants. Its effect is to render the affected variable immutable. Attempting to change the value of a final-qualified variable results in a compile-time error. Since constants cannot be changed, it is desirable to define only one instance of them for the class; hence constants should be declared with the static modifier as well. (DCL31-J. Qualify mathematical constants with the static and final modifiers)

The following code fragment demonstrates the use of static and final to create a constant:

...