aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Order of argument evaluation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Order of argument evaluation" Watch "Order of argument evaluation" New topic
Author

Order of argument evaluation

Aniket Patil
Ranch Hand

Joined: May 02, 2006
Posts: 218

When this code is run, the output is:
In outer class m1()
G.s12

Why does the call to m1() execute before printing the String variable? Should't the method arguments be evaluated from left to right? Also, the return value from m1 prints after the String value.


SCJP 5.0 | SCWCD 1.4 <br /> <br />If you don't know where you are going, any road will take you there!
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Sorry, I find your question confusing: both m1() methods have no arguments. If you mean the System.out.println() it only has one argument, and that is just the concatenation of two strings (or rather a string and int converted to string).

Are you getting confused between the return value of the function m1() in the outer class and its sideeffect of printing a line?
[ September 30, 2006: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
If you ask for when the argument expressions are evaluated, here is some information from JLS3
15.12.4 Runtime Evaluation of Method Invocation

At run time, method invocation requires five steps. First, a target reference may be computed. Second, the argument expressions are evaluated. Third, the accessibility of the method to be invoked is checked. Fourth, the actual code for the method to be executed is located. Fifth, a new activation frame is created, synchronization is performed if necessary, and control is transferred to the method code.
.....
The argument expressions, if any, are evaluated in order, from left to right.
Aniket Patil
Ranch Hand

Joined: May 02, 2006
Posts: 218
I got it, thanks a lot!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Order of argument evaluation