Home Tutorial Java Corejava Difference between the local and class variable.

 
 

Share on Google+Share on Google+
Difference between the local and class variable.
Posted on: June 25, 2010 at 12:00 AM
Advertisement
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);
  }
}
Advertisement

Related Tags for Difference between the local and class variable.:


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.

Posted on: June 25, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com