10/01/2008

Instance variable / class variable

Variables, which is not inside a method, in a class is called instance variables.
With the keyword static, it is called a class variable, which is not dnamic.

example

Class Sample {

int x = 1;   // instance variable
static int y = 2;  // class variable

public static void main(String[] args) {

Samepl sample = new Sample();

System.out.println(sample.x);
System.out.println(Sample.y);

}
}

How to refer to static variables:
Class name dot variable name

How to refer to dynamic variables:
Object dot variable name