class Test {
public static void main(String arg[]) {
System.out.println("**MAIN METHOD");
System.out.println(Mno.VAL); // SOP(9090)
static final int
field is a compile-time constant and its value is hardcoded into the destination class without a reference to its origin; In specific detail, the compiled bytecode corresponds to this:
public static void main(String arg[]){
System.out.println("**MAIN METHOD");
System.out.println(9090)
System.out.println(9190)
}
As soon as you remove final
, it is no longer a compile-time constant and the special behavior described above does not apply. The Mno
class is loaded as you expect and its static initializer executes.