gurpeet singh wrote:hi Sarvesh. you need to understand how the arguments gets passed to methods in java. if you are aware of C++ you might remember we used to talk about Pass By Value or Pass by Reference . so what is the case in java. if you want to BURN something in your mind(as you say) then burn that java is PASS BY COPY OF VALUE. what does that mean ? let me explain using your CardBoard example.
Consider the statement CardBoard c3 = go(c2);
now according to you c2 gets passed in go method which assigns it to null. this is wrong. actually a copy of c2 is made and that copy is passed to go method. so in go method that copy of c2 is assigned to cb which gets initialized to null. so as you say c2 is NOT null. c2 still points to CarbBoard.
Same thing with the box example. i left it to you to figure it out .
Henry Wong wrote:https://coderanch.com/how-to/java/CallByReferenceVsCallByValue