The output "10,0,20" is justified.
In this whole flow, two objects of ValHold() have been created
one in amethod() - object1(say)
and one in another() - object2(say)
Now in total there are three references(handles) to these two objects.
1. reference v in amethod() - pointing to object1
2. reference v in another() - intially pointing to object1, and afterward pointing to object2
3. reference vh in another() - pointing to object2
Now let's see how the flow goes :
amthod() execution
1. object1 is created and modified with new i value of 30 with handle v
another() execution
2. reference v of another() method modifies object1 with i = 20
3. object2 is created with default value of i=10
4. refernce v of another() points to object2 now
5. i value of object2 is printed (which is 10)
6. local variable i is printed (which is 0)
amethod()
7. reference v of amethod() is still pointing to object1 whose current i value is 20
i value of object1 is printed (which is 20)
Conclusion:
Java does manipulate objects by reference, and all object variables are references.
However, Java doesn't pass method arguments by reference; it passes them by value.
hope that helps !
Kamal