How does Java assign value to final object System.out?

Viewed 66

Consider the below Java code,

import java.io.File;
import java.io.PrintStream;

public class Test {

    public final static PrintStream out = null;

    public static void main(String[] args) throws Exception {
        Test.out = new PrintStream(new File("/tmp/temp.txt"));
    }

}

It leads to below compilation error.

Test.java:9: error: cannot assign a value to final variable out
        Test.out = new PrintStream(new File("/tmp/temp.txt"));
            ^
1 error

The in-built java.lang.System class also has a similar declaration as shown below:

public final static PrintStream out = null;

Could somebody let me know how does this System.out get initialized?

0 Answers
Related