Which statement is true?

Given the code fragments:

And,

Which statement is true?
A. After line 11, three objects are eligible for garbage collection.
B. After line 11, two objects are eligible for garbage collection.
C. After line 11, one object is eligible for garbage collection.
D. After line 11, none of the objects are eligible for garbage collection.

Download Printable PDF. VALID exam to help you PASS.

3 thoughts on “Which statement is true?

  1. C is correct

    GarbageCollector gc1 =new GarbageCollector();
    GarbageCollector gc2 =new GarbageCollector();
    GarbageCollector gc3 =new GarbageCollector();
    gc1=gc3;
    gc3=gc2;
    gc2=null;
    System.out.println(gc1.toString());
    System.out.println(gc3.toString());
    System.out.println(“gc1 == gc3 : ” + gc1.equals(gc3));
    System.out.println(gc2.toString());

    ==================================================

    [email protected]
    [email protected]
    gc1 == gc3 : false
    Exception in thread “main” java.lang.NullPointerException: Cannot invoke “Object.toString()” because “gc2” is null
    at com.testengine.web.GarbageCollector.main(GarbageCollector.java:16)

Leave a Reply

Your email address will not be published. Required fields are marked *