• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Println

 
Sankar Vaiyapuri
Greenhorn
Posts: 3
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In System.out.println() the System is a Class and out is a static instance of PrintStream in System class. println() is a method in PrintStream class. So the method println() is called using System.out. But the out instance is static,final and it is initialized to null in System class. Then how it calls println() method?
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What makes you think it is initialised to null?
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java source code from src.zip. From the source of java.lang.System:
However, elsewhere we see this:
This method in turn is called when the class is loaded:
And that's how in the end System.out is initially set.

Note that although System.in, System.out and System.err are final, the JVM still is able to change them through System.setIn, System.setOut and System.setErr. That's because it uses native code to do so, and the JVM can do a lot through native code that we can't.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic