🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: JVM Memory and Garbage Collection: all 10 questions

Quiz: JVM Memory and Garbage Collection · Question 5 of 10

Two objects reference only each other, and no variable points to either. What happens?

Two objects reference only each other, and no variable points to either. What happens?

  1. A.They are never collected, causing a leak
  2. B.The program throws an error
  3. C.Both are eligible for garbage collection
  4. D.Only one of them is collected
Answer & explanation

Correct answer: Both are eligible for garbage collection

Reachability is checked from GC roots, so a cycle with no path from a root is collected.

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 →