Skip to content

What a method can change

Watch it run · 1 of 3

Try to change both

1public class Main {
2 static void tryToChange(int x, int[] arr) {
3 x = 99;
4 arr[0] = 99;
5 }
6
7 public static void main(String[] args) {
8 int n = 5;
9 int[] box = {5};
10 tryToChange(n, box);
11 System.out.println(n + " " + box[0]);
12 }
13}

Memory

int n

5

Output

(nothing yet)

line 8n holds 5.

step 1 of 5