• Post Reply Bookmark Topic Watch Topic
  • New Topic

println  RSS feed

 
Jill Derrieux
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the best way to explain using System.out.println vs out.println??
 
J Steven Perry
Greenhorn
Posts: 13
Android Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not totally sure what your question is, so I will explain the usage of System.out.println() and out.print() (where out is a local variable set to System.out):



System.out is a public static member of the java.lang.System class that contains (among many other things) a static method called println(). To use out.println(), we have to declare a variable of type PrintStream called "out" to hold a reference to System.out.

Why you would want to do this escapes me, but there it is.

--jsp

Output:

 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

As Steven has already said it's not clear what your question actually means. If Steven hasn't already provided you with the answer please provide more detail so we can hep you.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chances are, you have seen a class with a static import. That is almost as if the imported member of the class were a private static member of your class. So you can use out by importing it from the System classRead a little more about static imports here.

The out field is a static member of the System class, but all its methods that I have seen are instance methods (not static), so you can't use static import twice and write println.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!