
Declare each variable only
once,the first time the
variable is used.After the
variable has been declared,
its data type cannot be
changed.
COMMON ERROR
TRAP
54 CHAPTER 2 Programming Building Blocks—Java Basics
you will receive a compiler error similar to the following:
twoCents is already defined
Similarly, once you have declared a variable, you cannot change its data
type. Thus, these statements:
double cashInHand;
int cashInHand; // incorrect, data type cannot be changed
will generate a compiler error similar to the following:
cashInHand is already defined
2.2.7 String Literals and Escape Sequences
In addition to literals for all the primitive data types, ...