• Post Reply Bookmark Topic Watch Topic
  • New Topic

System.out.println()  RSS feed

 
Sathy thyagaraj
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can we access the println() from Printstream class from System class. 'out' is the field in the System class.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like a beginners' question to me.

You don't actually call println() from the System class.

Have you looked in the API, and looked up java.lang.System, then what "out" represents in the System class, then what class "out" is, then the methods of "out?"

When you have done that, you ought to have some more idea of the answer to your question. If you haven't worked it out, come back and tell us what you think.



CR
 
Sathy thyagaraj
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question is , How it happens in java System.out.println(). out is predefined variable in System class. how it calls println();
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct that "out" is a predefined variable of the System class. Since it is "static" (look in the API for System) there is only ever one copy of "out" and all calls to "out" call the same object.

Look up PrintStream and you will find that "out" has a method called println(), which is overloaded. What you are doing is calling a [static] field ("out") of the class System, then calling a method ("println()") of that object.

Any help?

CR
 
Sathy thyagaraj
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank U Campbell

sathy
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!