I am really confuse why in this small example i is still 0:
public static void main(String[] args) {
int i = 0;
inc(i);
System.out.println(i);
}
private static void inc(int i) {
i++;
}
probably very easy question but I dont see it
Java passes parameters by value.
So the
iin the methodincis really just a copy of the “original”iin themainmethod. You increment that copy, but that has no influence on the original variableioutside.See this question for a more detailed explanation.