Which are true of the following code? (Choose all that apply)
1:import java.util.*; 2:public class Rectangle { 3: public Rectangle(String n) { 4: name = n; 5: } 6: public static void main(String[] args) { 7: Rectangle one = new Rectangle("g1"); 8: Rectangle two = new Rectangle("g2"); 9: one = two; 10: two = null; 11: one = null; 12: } 13: private String name; 14:}
C, D, F.
The code above compiles without issues. So G is not correct. F is correct.
Immediately after line 9, only Rectangle g1 is eligible for garbage collection since both one and two point to Rectangle g2.
Immediately after line 10, there still only Rectangle g1 is eligible for garbage collection. Reference one points to g1 and reference two is null.
Immediately after line 11, both Rectangle objects are eligible for garbage collection since both one and two point to null.