Please wait ......

Declaring variables

Learn about various kinds of variables in Java


There are 3 major kinds of variables.

  1. Variables declared as a member of a class are called fields
  2. Variables within a method or block of code - local variables
  3. Variables in method declaration - parameters

This is illustrated in the image below.

 

Member variable (Field) declaration:

The declaration of a member variable should be      MODIFIERS        TYPE         FIELDNAME.   As an example,