When passing the valHold instance into a method, (Since it is an object, pass - by reference will occur), it will create another copy of reference. Name of that reference is also v. because in the method definition, valHold parameter name is v. But these two references will be different. but referring to same object.
And v mentioned in the method definition will be local to method 'another'. In the method another(), you are changing the value of v as 20. So original object's i value get changed to 20.
when v = vh, local v i.e. the parameter v mentioned the another() method definition will get changed.
No change for the v in the amethod(). it iwll points to the same object.
So, we will get the anwer 20 for the third sysout.
Howdy, Anju. First of all, I'd like to welcome you to our JavaRanch!
Now, Mohammad, I'd kindly like to ask you to carefully choose the appropriate forum before asking a question. Also, please choose a meaningful subject line for your question. This way, the forum is better organized, you get a good answer for your question faster and it is also able to help more people that have the same doubt as you! For general informations about how to ask questions here in the ranch, please take a look here.