I've just started learning Java and I had a question about some practice code I was looking at. Essentially, I'm unable to understand why our output in this case is 7 14 as opposed to 14 14. The code is the following:
class Test {
static int s;
public static void main (String [] args)
{
Test p = new Test();
p.start();
System.out.println(s);
}
void start()
{
int x = 7;
twice(x);
System.out.print (x + " ");
}
void twice (int x)
{
x = x* 2;
s = x;
}
}