← Quiz: JVM Memory and Garbage Collection: all 10 questions
Quiz: JVM Memory and Garbage Collection · Question 6 of 10
In this code, how many Box objects are eligible for GC at the end of main's body? (code)
In this code, how many Box objects are eligible for GC at the end of main's body?
Box x = new Box(); // object 1
Box y = new Box(); // object 2
x = y;
y = null;
- A.0
- B.2
- C.1
- D.It cannot be known
Answer & explanation
Correct answer: 1
Object 1 lost its only reference when x was pointed to object 2. Object 2 is still reachable through x.
Can you get the rest right without peeking?
Take the timed Quiz: JVM Memory and Garbage Collection quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →