posted 20 years ago
public void another(ValHold v, int i){
i=0;
v.i = 20;
** sets i = 20 (this v refers to the v in amethod()
ValHold vh = new ValHold();
v = vh;
** this changes the reference ValHold v (the one in the parameter) from the reference it had with the v in the amethod(), to a new instance vh,
now v.i=10
System.out.print(v.i);
** prints out 10, as we stated from above
System.out.print(i);
** i never changed, only v.i was set to 20, so prints out 0
public void amethod(){
.
.
.
another(v,i);
System.out.print( v.i );
}
** returning from the another method, we have v.i = 20 which was set here
public void another(ValHold v, int i){
i=0;
v.i = 20;
hope this helps