← Back to Study Guide← 返回学习指南

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代码

  1. int x = 5;
  2. int[] a = {5};
  3. int p = x; // call: p is a copy of the value
  4. int[] q = a; // call: q is a copy of the reference
  5. p = p + 1;
  6. q[0] = q[0] + 1;

State状态

Variable变量Value值
x5
a—
p—
q—

Use ← and → to step. The note explains each change.使用 ← 和 → 逐步运行。每次变化见下方说明。