This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Customer Requirements for Developers and have Marcho Behler on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Doubt about the ouput of this program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Doubt about the ouput of this program" Watch "Doubt about the ouput of this program" New topic
Author

Doubt about the ouput of this program

asha ganapathy
Ranch Hand

Joined: Nov 03, 2006
Posts: 54
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

Joined: Aug 07, 2007
Posts: 2713
    
  56
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.
 
subject: Doubt about the ouput of this program
 
It's not a secret anymore!