Java Reference
In-Depth Information
Local Variable Declaration
Type
Variable Declarator
;
final
,
Variable Declarator
Identifier
=
Expression
Array Initializer
A variable declaration consists of a Type followed by a list of vari-
ables. Each variable can be initialized in the declaration to the value of
the specified Expression. If the final modifier precedes the declaration,
the identifiers are declared as named constants whose values cannot
be changed once set.
Examples:
int total;
double num1, num2 = 4.356, num3;
char letter = 'A', digit = '7';
final int MAX = 45;
LISTING 2.5
//********************************************************************
// PianoKeys.java Author: Lewis/Loftus
//
// Demonstrates the declaration, initialization, and use of an
// integer variable.
//********************************************************************
public class PianoKeys
{
//-----------------------------------------------------------------
// Prints the number of keys on a piano.
//-----------------------------------------------------------------
public static void main (String[] args)
 
Search WWH ::




Custom Search