Search code examples
javafinal

When is the out object of the System class initialized in Java?


Variables modified as final must be initialized when declared or when the constructor is executed.

I looked up in the System Class File, and found the out Object is initialized in the private static void initializeSystemClass() method, when is this method called?


Solution

  • private static native void registerNatives();
    static { registerNatives();
    }
    

    in the System.java file, we can see this code in the head line. it invokes the registerNatives Method, it will let the VM to call the initializeSystemClass Method to initialize the System Class.