Variable Declaration

Date: 1/28/2002

Declaration

A declaration starts with the type of the variable, followed by the name of the variable.  A variable name starts with a lower-case, then is proper-cased.

When declared inside of a method, a scope is not specified. These are automatically local variables.

When declared outside of a method, the scope should be specified.

Scope

Statement of scope comes before the type.  Scope applies only to variables declared outside of the methods, also known as class-level variables. The types of scope are:

Class level variables without a statement of scope are protected.

Initializing

It is a good habit to set a variable to a value, even if it is null, at the time it is declared.  On occasion, variables declared inside a method that are not initialized will cause a compile-time error.