Prasanna Raman wrote:Thank you, Jeff! I am now able to understand it. But now I get another question, from where can we ever call a method without using an object?
How can we just equate something to a method() just like that without using an object to call that method?
You mean that
... = nullPrintStream(); line? It just means a method in the current class. If nullPrintStream() is static, it's equivalent to
<my class name>.nullPrintStream(), so in this case, it would be equivalent to
System.nullPrintStream(). If it's a non-static method, it's equivalent to
this.nullPrintStream(), but since we're in a static context there, there is no "this", so it must be a static method.
Also, when exactly does final static out get start pointing to the PrintStream object? When exactly is the line of code you wrote executed?
When the class is loaded, all the static initialization lines and static initialization blocks are executed in the order they appear in the source file. The class is loaded the first time it is referred to in our code, although some core classes, like Object, Class, String, System, etc. are loaded by the JVM before our main() is ever called.