Java is technically considered pass-by-value.
Here's why it can be confusing:
- In Java, primitive data types (like
int
ordouble
) are directly copied and passed by value to methods. - For objects (which are references), a copy of the reference is passed, not the object itself. This reference points to the object's location in memory.
So, while you might think modifying an object passed to a method would change the original object (pass-by-reference behavior), it actually only modifies the copy of the reference within the method. The original object remains unchanged.