This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Assume my class is a class that has 2 methods f() and g().How many objects will be eligible for garbage collection by the time you invoke g() ? Myclass c1 =new Myclass(); Myclass c2 =new Myclass(); f(c1); c1 = null; c2 =c1; g();
1) 0 2) 1 3) 2 4)The given information is insufficient.
My opinion is 2 objects are eligible for garbage collection.Am i right or wrong?please correct me.
i've always been a little shaky on GC, but i'd think 4 would be the right answer. mostly because you don't know what f() is doing with the reference. it is possible that object gets a new reference in that method, and would then therefore not be eligible.
I'm willing to listen to someone tell me why i'm wrong, though.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors