Multiple choice technology programming languages

. Which line of the following code would make the test object eligible for garbage collection? (Line numbers are included only for clarity's sake) 1. public class Garbage { 2. public static void main(String [] args) { 3. StringBuffer test = new StringBuffer("hello"); 4. System.out.println(test); 5. test = null; 6. } 7. }

    1. 3
    1. 4
    1. 5
    1. No lines enable the garbage collection of the test object.
Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

An object becomes eligible for garbage collection when there are no more references to it. Line 3 creates the StringBuffer referenced by test. Line 5 sets test to null, removing the only reference. The StringBuffer is now eligible for GC.