~/ 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/e5b5d7b5-0da2-43fc-a3dc-0d88be881a61/flashcard utf-8 LF