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.
Naseem Khan
Ranch Hand
Joined: Apr 25, 2005
Posts: 809
posted
0
Originally posted by srilatha rao: So, the value of output variable is "134" before calling foo(1) and "1342" after calling foo(1).
What about finally. finally will always be executed even at second time.
Oh, I am sorry, yes, the output is "13423". finally will be executed in the second time also. Thanks
S Thiyanesh
Ranch Hand
Joined: Mar 19, 2006
Posts: 142
posted
0
output is 13423
krish bajaj
Ranch Hand
Joined: Jun 19, 2006
Posts: 31
posted
0
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
Shiaber Shaam
Ranch Hand
Joined: Jun 16, 2006
Posts: 252
posted
0
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....
krish bajaj
Ranch Hand
Joined: Jun 19, 2006
Posts: 31
posted
0
hello shiaber
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