Originally posted by brij tiwari:
For the first call with foo(0), the finally block prints the output value then returns the output value which is then printed by the system.out call in main method.so value 'b' is printed two times.
For second call with foo(1),the catch block make output as 'ba' and returns 'ba' to main method, but before returning finally block is called always...so before printing the returned value i.e. 'ba' first finally block prints the 'bab' value...after that since the return value is 'ba' only thats y main prints 'ba'
so the sequence is
b
b
bab
ba
Why the modification done to output in finally gets lost?
I mean why output is not
b
b
bab
bab
Why the modification done to output in finally gets lost?
b
b
bab
bab
Vikas Chandra Roy
Originally posted by Vikas Roy:
Hi Ranchers,
I have one doubt about the given explanation.
How come the catch block construct the String as " ba", actually it is only appending "a" in output object.
I have not tried the code, but according to me the output should be " ab" becouse whenever try executes and throws some exception, catch block executes before finally block.
Please do correct me or explain me.
Regards,
How come the catch block construct the String as " ba", actually it is only appending "a" in output object.
We can walk to school together. And we can both read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|