~/ learn/ java-from-zero/ cards/ Pass-by-value: the most-misunderstood Java rule
1 of 4

Type a method that mutates through the reference (visible to caller)

Type a method that mutates through the reference (visible to caller)

Answer

static void zeroFirst(int[] arr) { arr[0] = 0; }

arr is a copy of the reference, but both point to the same array. Setting arr[0] mutates the shared object — the caller sees the change.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/e17f6566-5fd0-4dc0-a6b0-8b23459362fb/flashcard utf-8 LF