previous | start | next

Syntax 4.2: Constant Definition

  In a method:
final typeName variableName = expression ;
 
In a class:
accessSpecifier static final typeName variableName = expression;

Example:

  final double NICKEL_VALUE = 0.05;
public static final double LITERS_PER_GALLON = 3.785;

Purpose:

To define a constant in a method or a class

previous | start | next