This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
When foo(0) is executed, the output value is "134", since catch block is not executed. When main method calls the foo(1) method, the output value continues with the "134" value, since output is static string variable.Only one copy of output is created. When foo(1) is executed, the output value is "1342", since in the catch block, there is a return statement. 3 and 4 values cannot be appended to the output variable. Here, return statement stops the execution of finally and outside the finally block code and returns to the main method.
So, the value of output variable is "134" before calling foo(1) and "1342" after calling foo(1).
As per my knowledge, the above analysis is correct. If there is any mistake, sorry for the reply.
hi all! tell me srilathawhy the statement afeter finally block not execute i understand upto 13423 but why not 4 i mean why not 134234 please help me
Joined: Jun 16, 2006
hi bajaj... if there occurs a return stmt in catch or finally block... the code in finally gets executed and the code after finally gets skipped.... I hope it will make sense....
Joined: Jun 19, 2006
just try this program without using return statement in catch block then after finally block statement execute easily Do not use number simply use write statement for understanding i did ur program and somewhere my concept is clear if u like my answer then well and good otherwise sorry because i am new player in this field