Hi ketki
now in the following code
lets see wat happens
the ball starts rolling in the main method
where amethod is called of ObParm class
now in amethod
we are creating an object of class Valhold
and setting its member variable to 30
Hope its okie for you till now
Now here is were you may be lost
now the next line
another(v,i);
in this method we are passing the reference created in amethod
Now in
java when you pass a reference variable into a method you are actually sending the path of the reference variable and you can access and change the value of the member variable of
class and it would be reflected in the method.
whereas if you change the reference variable itself and you are making any change it wont be reflected it is as you are creating a new reference variable
well lets take it in this way
v.i = 20;
here you are accessing the variable i of ValHold class this change would be reflected above in the amethod
the value of i would be set to 20 from 30
now here
v = vh;
you lost the address of the object
it is not accessible now in this method
hence the value of the variable i stays 20