- Below is example code you can show to students.
- Students might expect that the variable
x
is changed by being passed to the method foo.
public class Example {
public static void main(String[] args) {
int x = 10;
Example.foo(x);
System.out.println(x); // prints 10
}
public static void foo(int y) {
y = y + 3;
System.out.println(y); // prints 13
}
}