All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.
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 :
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
}
}
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.