File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt about the ouput of this program

 
asha ganapathy
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to know why the output of this program is
finally : 101
After return : 100


Thanks a lot in advance
 
Tony Docherty
Bartender
Pie
Posts: 2878
59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because x++ is post incrementing the variable 'x'. ie The current value in 'x' (100) is taken as the return value and then 'x' is incremented. But before the method returns the finally clause is executed which prints out the new current value of 'x' (101).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic