The program below prints (20,10) but I do not understand why it is not (10,20), as the foo method should switch the variables.
Could somebody please explain this? Thank you
public class Test
{
public static void main(String[] args)
{
int x = 20;
int y = 10;
foo(x,y);
System.out.println(x + " , "+y);
}
public static void foo(int x, int y)
{
int tmp = x;
x = y;
y = tmp;
}
}