The finally block is always executed.

if you were to try

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();
        int a= testfinal.dist;
        System.out.println("    dist           " + j );
        System.out.println("    dist           " + a );
     }

}

//output should be
//35
//12

This is because your getresult() method returns 35. whilst your finally
block assigns 12 to dist.

Take notice of the *return *statement.



On Mon, Mar 22, 2010 at 7:33 AM, 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.

Reply via email to