How does System.out.println() works?
Printable View
How does System.out.println() works?
Are you talking about the underlying implementation? Or just the semantics of the calling syntax? if it's the latter, see How Does System.out.println work in Java
Interesting link. I'm not sure I really agree with how they described it though. One thing really stuck out to me:
Sure, out is a static variable. But it has nothing to do with the dot operator, or being unable to call methods on whatever is returned from another method. The biggest sign that it's a variable and not a method is simply the lack of () after it.Quote:
Now, how do we categorize 'out'? Since println() is clearly a method, and its called using 'out', then we know that 'out' can not possibly be a method because it doesn't make sense to have one method invoke another method with the dot operator in Java. This means 'out' must be a variable.
To say that it doesn't make sense to have one method invoke another is simply wrong. Actually, this happens all the time. Here are a few examples:
Code java:
I'm pretty skeptical about that programming interview site in general. I would say your first step to figuring out how System.out.println() works is to trace through the API:
System
.out
.println()
Hi guys, thanks for the correction of the mistake - I am the owner of the site, and I have updated the page to reflect the correct information.
Of course, my opinion is biased but I think Software interview questions is a great site - and have received much input agreeing with that claim. I do try my best to clean up any errors - and I really appreciate you pointing this one out. If you see anything else please let me know.
Thanks!