Primitive vs reference parameters基本类型参数与引用参数
Run one Java statement or condition check at a time. Watch x, a, p, and q change.每次执行一条 Java 语句或检查一次条件,观察 x、a、p、q 的变化。
Code代码
- int x = 5;
- int[] a = {5};
- int p = x; // call: p is a copy of the value
- int[] q = a; // call: q is a copy of the reference
- p = p + 1;
- q[0] = q[0] + 1;
State状态
| Variable变量 | Value值 |
|---|---|
| x | 5 |
| a | — |
| p | — |
| q | — |
Use ← and → to step. The note explains each change.使用 ← 和 → 逐步运行。每次变化见下方说明。