Originally posted by Suguna Gollapally:
...1)An object will be garbage collected when it becomes unreachable
True : When object is not reachble its eligible for GC right
2) An object will be garbage collected if it has null assigned to it
false...
I would answer "false" to number one. Yes, an object is
eligible for GC when it is no longer reachable, but the question asks whether it
will be collected, and that is not guaranteed.
Question two is a little peculiar. You don't assign null to
objects -- you assign null to
variables that might otherwise reference objects. Now, if the question said something like, "An object will be garbage collected if any
reachable references to it are replaced with null references..." Well, even then we would be back to the situation in question one. It would be eligible, but not necessarily collected.
I'm curious: Where are these questions coming from?
[ December 02, 2006: Message edited by: marc weber ]