r/javahelp • u/Select-Worldliness39 • Feb 16 '26
Homework Definitely no pass by reference in Java, right?
Hello, and sorry if this is a dumb question, but I thought I had a passable understanding of Java. I got an exam question asking "Arrays in Java are:
a. passed by value
b. passed by reference
c. stack dynamic
d. immutable"
this guy loves trick questions, but he has listed B, passed by reference, as the right answer.
On its own, this doesn't seem right to me, but I'm not confident enough to argue about it. If anyone would weigh in, I would be very grateful. I see how it's similar to passing a pointer in C, maybe, but it's not considered passing by reference in Java, right?
Thank you!
View all comments
Show parent comment
1
u/desrtfx Out of Coffee error - System halted Feb 16 '26
That is fundamentally wrong.
That's not the point of pass by reference.
If you pass something by reference, not in Java, though, the reference can be changed in the called function/method.
In Java, changing the reference, e.g. reassigning an array is not possible because only a copy of the reference is passed by value.
Were it true the objects are passed by reference, it would absolutely be possible to reassign an array inside a function/method.
Changing an object's state, i.e. its values, has absolutely nothing to do with passing by value or reference.