Given:
4. class MyClass { Long acctNum, password; } 5. public class Main { 6. public static void main(String[] args) { 7. new Main().go(); 8. // do more stuff 9. } // www .ja v a2s .c o m 10. void go() { 11. MyClass a1 = new MyClass(); 12. a1.acctNum = new Long("1024"); 13. MyClass a2 = a1; 14. MyClass a3 = a2; 15. a3.password = a1.acctNum.longValue(); 16. a2.password = 4455L; 17. } }
When line 8 is reached, which are true? (Choose all that apply.)
A. a1.acctNum == a3.password B. a1.password == a2.password C. Three objects are eligible for garbage collection. D. Four objects are eligible for garbage collection. E. Six objects are eligible for garbage collection. F. Less than three objects are eligible for garbage collection. G. More than six objects are eligible for garbage collection.
H:Note
B and D are correct.
B is correct, although when line 8 is reached, the references are lost.
D is correct because only one MyClass object is created, and a1, a2, and a3 all refer to it.
The MyClass object has two Long objects associated with it, and finally the anonymous Main object is also eligible.