Hi, I'm just going through the marcus green mock 2:
Given the following code what will be the output?
class ValHold{
public int i = 10;
}
public class ObParm{
public static void main(
String argv[]){
ObParm o = new ObParm();
o.amethod();
}
public void amethod(){
int i = 99;
ValHold v = new ValHold();
v.i=30;
another(v,i);
System.out.print( v.i );
}//End of amethod
public void another(ValHold v, int i){
i=0;
v.i = 20;
ValHold vh = new ValHold();
v = vh; //LineX
System.out.print(v.i);
System.out.print(i);
}//End of another
}
1) 10030
2) 20030
3) 209930
4) 10020
The answer is 4)
can someone explain this to me please?.
I thought the assignment "v = vh;" at //LineX would mean v.i would equal 10
so:
10010
?
Any help would be much appreciated!
Rowan