Section 7.9 Pass-By-Value vs. Pass-By-Reference

• When an argument is passed by reference (p. 265), the called method can access the argument’s value in the caller directly and possibly modify it.

• All arguments in Java are passed by value. A method call can pass two types of values to a method—copies of primitive values and copies of references to objects. Although an object’s reference is passed by value (p. 265), a method can still interact with the referenced object by calling its public methods using the copy of the object’s reference.

• To pass an object reference to a method, simply specify in the method call the name of the variable that refers to the object.

• When you pass an array or an individual array element of a reference type ...

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.