All parameters in Java are passed
by value. This means that the value of the actual parameter can never be changed as a result of calling a method.
The catch is if you pass an object reference. The actual parameter is the
reference, not the object. That means that while you cannot change the reference and make it refer to another object, you can still change the
object being referenced. Clear as mud?
Notice that even though in foo(), str is made to reference a new string, the actual parameter bar in
test() does not change. To illustrate further with mutable objects, let's look at some code that passes around arrays, since arrays behave like objects in Java.
HTH
[JL: corrected for loop; was missing increment]
[ June 12, 2004: Message edited by: Junilu Lacar ]
[ June 14, 2004: Message edited by: Junilu Lacar ]