Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

What is the true story about how parameters are passed in Java? Is is by value or by reference?

0
Posted

What is the true story about how parameters are passed in Java? Is is by value or by reference?

0

. All parameters (values of primitive types, & values that are references to objects) are passed by value [JLS sect 8.4.1]. However this does not tell the whole story, as objects are always manipulated through reference variables in Java. Thus one can equally say that Objects are passed by reference (and the reference variable is passed by value). This is a consequence of the fact that variables do not take on the values of “objects” but values of “references to objects” as described in the previous answer. Bottom line: primitive type arguments (int, char, etc) _do not_ change when the corresponding parameter is changed. The fields of object type arguments _do_ change when the corresponding parameter fields are changed.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123