[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Originally posted by Jim Soong:
... If node is passed by val in line "a=moveNode(a,node);", first System.out should print "1", and second System.out should print "2"...
But moveNode(a,node) does have the effect of setting node.next = a, becaue although toAdd is a local variable, it's still referencing the same object, whose variables (in this case, next) can be modified.
So the assignment node = node.next sets node = a. But because a.element was never explicitly set, node.element is now equal to the default initialization value of 0.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Originally posted by Jim Soong:
... If move(Node target, Node source) does change the value of node in split, how should pass by val explained here? ...
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Originally posted by marc weber:
Basically, method arguments are copies of references, and these copies are local to the method.
So if I have myRef = someObject and I call myMethod(myRef), then myRef becomes a local variable within the scope of myMethod. It is a different variable than the "myRef" outside of the method. However, both of these variables are still pointing to the same object. So within the method, if I say myRef.var = 7, this will modify the object itself, and that change will be visible through all references pointing to that object.
On the other hand... Within the method, if I say myRef = someOtherObject, then this assignment is valid only within the method (because that's the scope of the local variable). I'm not changing the object -- I'm just re-assigning the local variable to point to a different object. Outside of the method, the other "myRef" is still pointing to someObject.
Originally posted by Jim Soong:
... Could you recommend a book or some url? ...
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org