Hi;)
Since I am doing last checks for my Exam,
I stumbled upon this exam question, which I
do not completely understand:
It asks what the Code outputs. It outputs "false."
As an Explanation it states: "Since
Java is pass by value, reassignments to method parameters are not seen by the caller."
I understand what that means, and I see, that primitives get "forgotten about" what they are not reassigned or saved
in a variable after the Method end, but I thought it's not the same with Objects...I thought that they still exist
with a changed state after they method (if the method actually changes the state...).
What I am especially interested of is what happens here:
When I pass in the toy5 Object, and this statements happens:
does the toy5 Reference (the one which was created with Toy toy5 = new Toy();)
now point to a new Toy Object in memory, and the original Object gets garbage collected?
Or does toy5 point to two Objects in memory (which I don't think)?
I hope someone can explain to me what happens there (as this confuses me the most):