public class ClearingDoubtsAboutStatic {
static
{
System.out.println("Static Block1 Output: "+ClearingDoubtsAboutStatic.statVar); //------Line 5
statVar=20; //-----Line 6
System.out.println("Static Block1 Output: "+ClearingDoubtsAboutStatic.statVar); //------Line 7
System.out.println("Static Block1 Output: "+statVar); //---Line 8
}
static int statVar=30;
public static void main(String[] args) {
}
}
What in my mind was that the line 7 and 8
will give the same output, but it is not the case.
My Question
what I don't understand is when we are able to initialize the static variable without the class name at line 6
but why we are not able to print it without the class name at line 8
?