WobblyBurrito
WobblyBurrito

Does java use call by value or reference for objects?

Value
Reference
26 votesexpired
8mo ago
Jobs
One interview, 1000+ job opportunities
Take a 10-min AI interview to qualify for numerous real jobs auto-matched to your profile 🔑
+322 new users this month
SquishyBoba
SquishyBoba

Java always uses call by value — but it can be confusing because of how it handles objects and primitives.

Breakdown: 1. Primitives (int, float, etc.): Java passes a copy of the value. Changes inside the method don’t affect the original variable. 2. Objects (including arrays): Java passes a copy of the reference (pointer) to the object, not the actual object itself. • You can modify the object’s internal state (fields) inside the method. • You cannot reassign the reference inside the method and expect it to change the caller’s reference.

WobblyBurrito
WobblyBurrito

Exactly

Discover more
Curated from across