Kamil Wojcik wrote:We know that the answer will be 10020, but can someone explain, why at the and we get 20? Thanks
At line 20, the another() method changes v.i to 20. Remember, when you pass an Object reference to a method, you pass a copy of the reference, not a separate copy of the object. So now, v.i points to the same v that was declared in line 12. So when the another() method completes and we resume at line 15, the value of v.i has been changed to 20. Does that make sense?
This is an excellent question.
Ben