Difference between the local and class variable.


 

Difference between the local and class variable.

This tutorial demonstrate the difference between the local and the class variable.

This tutorial demonstrate the difference between the local and the class variable.

Description:

The class variable are declared in the class but not within methods of any class. Whereas the local variable exits within the methods of any class. Below two program are shown which help you to understand the difference between the class and local variable.

Showing Local Variable

public class LocalVar {
  public static void main(String args[]) {
    int localvariable = 101;
    System.out.print(localvariable);
  }
}

Showing the Class Variable

public class ClassVar {
  private static int classVariable;

  public static void main(String args[]) {
    classVariable = 101;
    System.out.print(classVariable);
  }
}

Ads