Site hosted by Angelfire.com: Build your free website today!
 

Variable Types

Three types of variables:

  • local variables.

  • instance variables.

  • class variables.

class MyClass {
      //This is a comment
      double salary = 45678.00; // instance variable
      static int totalcount = 0;  //class variable

      public static void main (String[] args) {
             Char male = 'm';   // local variable
      }
}
  • Class and instance variables are defined outside of any method.

  • Local variables are defined inside a method.

  • The scope of class and instance variables is anywhere within the class, as well as any method.

  • The scope of a local variable is only within the block of code in which it is defined.

  • Class variables are static.