I believe the answer is 2. Is my answer correct ? Why I am confused is the question asks for objects eligible for GC. Is String literal "hello" also an Object ?
posted 9 years ago
Hi Answer to the given problem should be 1. Here actually two objects are created ,one is in String pool and one other but both will be in the heap.Only object other than String pool is eligible for garbage collected.Objects in String pool remains in the heap.They are not collected by G.C.
Please post your query in SCJP forum ,Not in this forum.