This is because when the loop encounter return key word it just out from there and no further statement is executed in that loop, In your case it return 35 and no finally block is executed.
On Mon, Mar 22, 2010 at 5:03 PM, vinay basavanal <[email protected]> wrote: > Hi all, > > I want explanation for the output of following programme > ,the output is 35, but i was expecting it to be 10 since finally gets > excuted at the end > > public class testfinal { > static int dist=0; > > public static int getresult(){ > try{ > dist=35; > return dist; > } > finally{ > dist=12; > } > } > > public static void main(String args[]) { > int j=getresult(); > System.out.println(" dist " + j ); > } > > } > > -- > To post to this group, send email to > [email protected] > To unsubscribe from this group, send email to > [email protected]<javaprogrammingwithpassion%[email protected]> > For more options, visit this group at > http://groups.google.com/group/javaprogrammingwithpassion?hl=en > > To unsubscribe from this group, send email to javaprogrammingwithpassion+ > unsubscribegooglegroups.com or reply to this email with the words "REMOVE > ME" as the subject. > -- To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en To unsubscribe from this group, send email to javaprogrammingwithpassion+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
