Monday, December 28, 2009

Static Block

PROGRAM

public class Lab
{

public static void main(String[] a) {
DataStructure t = new Lab();
DataStructure t1 = new Lab();
System.out.println("Main");
}

Lab() {
System.out.println("Constructor");
}

static {
System.out.println("Static");
}
}

OUTPUT
Static   --> Static block is executed as soon as JVM loads the class and only once
Constructor
Constructor
Main

No comments: