Java Reference
In-Depth Information
Use the assignment operator (=) to change the value of a variable.
int luckyNumber = 13;
If you want to change the value of the variable, simply assign the new value:
luckyNumber = 12;
The assignment replaces the original value of the variable (see Figure 1 ).
In the Java programming language, the = operator denotes an action, to replace the
value of a variable. This usage differs from the traditional usage of the=symbol, as a
statement about equality.
Figure 1
Assigning a New Value to a Variable
36
37
Figure 2
An Uninitialized Object Variable
It is an error to use a variable that has never had a value assigned to it. For example,
the sequence of statements
int luckyNumber;
System.out.println(luckyNumber); // ERRORȌuninitialized
variable
Search WWH ::




Custom Search