datatype name_1, name_2, ... ,name_n
You can declare variables anywhere in a method where
a statement is valid. The variable's scope will be from the
point of declaration to the end of the control structure that contains
the variable. Commonly, variables are declared at the beginning
of methods (and have scope for the duration of the method) or
in the initialization of a loop (and have scope during the loop).
- The first variable declaration above creates a new variable with
name name of type datatype. The datatype
is either a primitive Java datatype, or it is a class name.
- The second declaration above creates and initalizes a new variable.
The initial value, val, must be an expression that evaluates
to a value of type datatype.
- You can initialize several variables of the same type using the
third declaration style above.
You can also declare variables in a class. These variables have
scope in all the class methods and exist as long as a class exists.
See the class declaration page for more
information on how to do this.
who is still writing this, would like to
hear your comments and suggestions.