int x = 8;
int y = x;
x = 4;
System.out.println(x + ", " + y);
Hello, I am trying to teach myself some basics of Java and I am currently looking at this example. In this, I know that the output will be: 4, 8
I however, do not know WHY that is the output, why is it that the first x comes out as a 4 and not an 8?
If I also change the int x to something else, it also makes the code incompatible. I would have thought that, as it seems to be different to the x = 4 parameter it would not matter if the int x changed?
If the int x is reliant in some way on the x = 4 line, why is the output then 4, 8 and not 8, 8? I do not know why x = 4 is having an effect on the rest of the code?
Thank you in advanced for any help in regards to this issue.