If we pass a reference variable to method and modify the object's state, the modifications are permanent (Please correct me if I am wrong). Consider the code:
class CardBoard {
Short story = 200;
CardBoard go(CardBoard cb) { //....(1)
cb = null;
return cb;
}
public static void main(String[] args) {
CardBoard c1 = new CardBoard();
CardBoard c2 = new CardBoard();
CardBoard c3 = c1.go(c2); //pass c2 into a method ....(2)
c1 = null;
// do Stuff
} }
When in the above code, we say cb=null and return cb, shouldn't c2 (and also c3) now have null reference? (PS: The original question asks for the objects that are eligible for gc after "//do stuff". The answer is given to be 2, but I am having problem in understanding it.)