Look at the code:
public class Test { public static void main(String[] args){ System.out.println("这是main方法"); System.out.println("---------------------分割线-------------------"); Outer outer = new Outer(); System.out.println("---------------------分割线-------------------"); System.out.println(Outer.Inner.a); } } class Outer{ public static int n = 2; static{ System.out.println("This is a static block of code!" ); } Static class Inner { public static int a = 10; // not exist until after the class is loaded a // public static Final a = 10; // Final at compile time there is If only a call will not load the static inner class static { System.out.println ( "this is a static inner class!" ); } } }
The result is:
Static inner class and normal class load order is the same: when the class is actively called, JVM will go to initialize the class ( https://www.cnblogs.com/DDiamondd/p/10963096.html )