You infact call the second method before the main method ends.
So you are right the main method fires first, but if you call something
else from the main method it will run the called bits from the main method.
<main()>
int z = foo(x,y);
System.out.println("x is " + x);
</main()>
To find the value of Z, it must run the method foo(x,y). It can't go on
untill it has the answer for the variable z.
However if you where to do something like ...
public static void main(String[] args) {
int x = 6;
int y = 3;
int z;
System.out.println("x is " + x);
z = foo(x, y);
}
Your out put would be right.
The reson for this is that you are finding the actual value for z after
you printout the results of x.