Because the return dist statement in a wrong position.

If you move return dist after finally block
    finally{
             dist=12;
         }
  here

it will work as you assuming.

Hope it helps.

Kind regards,
Saidamin Usmanov



vinay basavanal 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] 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.

Reply via email to