Java Interview Question

Is Java pass by value or pass by reference?

Updated 2026-07-10 · Beginner friendly
Quick answer

Java is always pass by value. For primitives, a copy of the value is passed. For objects, a copy of the reference is passed, not the object itself. This means a method can change the object that a reference points to, but it cannot make the original variable point to a different object.

Why this confuses people

Because you can change an object inside a method, many think Java is pass by reference. But what is actually passed is a copy of the reference. Both copies point to the same object, so changes to the object are visible, yet reassigning the copy does not affect the original.

void change(int[] arr) {
    arr[0] = 99;        // visible outside, same object
    arr = new int[3];   // reassigns the copy only, not seen outside
}

In the example the element change is visible because both references point to the same array. The reassignment is not visible because it only changes the local copy of the reference.

In the interview

The precise answer is Java is strictly pass by value, but for objects the value passed is a reference copy. Saying it this exact way avoids the common trap and shows you truly understand it.

Want the full Java guide?

Read every Java concept with notes, diagrams, and code in one place. Track your progress as you go.

Open the Java guide All Java questions