In Java, how does System.out.println() work? This question is - TopicsExpress



          

In Java, how does System.out.println() work? This question is an excellent example of how just some very basic knowledge of Java can lead you to the correct answer. Most interviewers would not expect you to know the answer to do this right away – but would like to see how you think and arrive at an answer. Marcus Aurelius (a Roman emperor) once said: Of each particular thing ask: what is it in itself? What is its nature?. This problem is an excellent example of how that sort of thinking can help one arrive at an answer with only some basic Java knowledge. With that in mind, let’s break this down, starting with the dot operator. In Java, the dot operator can only be used to call methods and variables so we know that ‘out’ must be either a method or a variable. Now, how do we categorize ‘out’? Well, ‘out’ could not possibly be a method because of the fact that there are no parentheses – the ‘( )’ – after ‘out’, which means that out is clearly not a method that is being invoked. And, ‘out’ does not accept any arguments because only methods accept arguments – you will never see something like “System.out(2,3).println”. This means ‘out’ must be a variable.
Posted on: Sat, 04 Oct 2014 11:37:15 +0000

Trending Topics



Recently Viewed Topics




© 2015