String returns in finally and try block

Viewed 599

I came across this question and I am unable to understand the reason of the output it is giving.

The program is:

public static String method(){

    String s = new String();
    try
    {
        s = "return value from try block";
        return s;
    }
    catch (Exception e)
    {
        s = s + "return value from catch block";
        return s;
    }
    finally
    {
        s = s + "return value from finally block";
    }

}

The output is:

return value from try block

Now, I debugged it and the value of s at return s statement in try block was return value from try block, return value from catch block after it returned from finally block.

Still the output is :

return value from try block

Can any one please explain this behavior?

3 Answers
Related