About Question com.enthuware.ets.scjp.v6.2.293 :
Posted: Fri Apr 29, 2011 5:23 pm
Although the answer remains the same the class is actually first referenced when executing the class file with the java command so if the code was changed to :
You would get the same answer. Line //1 does not actually cause the static init blocks to run as they were already run in order to execute the main method is called.
Code: Select all
public class StaticTest
{
static
{
System.out.println("In static");
}
{
System.out.println("In non - static");
}
public static void main(String args[ ])
{
System.out.println(" 1 ");
StaticTest st1 = new StaticTest(); //2
System.out.println(" 2 ");
StaticTest st2 = new StaticTest(); //3
}
}