Constant Declaration

A constant-declaration has either of the following syntaxes.

name = constant-expression;

name : primitive-type = constant-expression;

The name must start with an uppercase letter and it cannot be the same name as a global constant. The constant-expression is an expression that contains only literal values or other constants.

The following example illustrates constant declarations.

constants
    SecondsInMinute = 60;
    SecondsInHour   = SecondsInMinute * 60;
    SecondsInDay    = SecondsInHour * 24;

Constants declared in this way can be used in the body of the method, providing a more meaningful representation than simply using literal values.

For details about promoting a local constant definition to a type constant and promoting a method value to be a local method constant, see "Promoting a Local Constant to be a Type Constant" and "Promoting a Method Value to be a Local Method Constant", respectively, in Chapter 4 of the Development Environment User's Guide.