Share on Google+Share on Google+

Difference between the local and class variable.

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


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;

Showing the Class Variable

public class ClassVar {
  private static int classVariable;

  public static void main(String args[]) {
    classVariable = 101;


Posted on: June 25, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.