Friday, February 18, 2011

Static variable initialization

Static variables if not initialized are initialized to 0.

public class Test {
static int age;
public static void main (String args []) {
age = age + 1;
System.out.println("The age is " + age);
}
}
So the above code compiles and runs printing out The age is 1.

No comments:

Post a Comment

Chitika