🎴 Flashcard Mode

Advanced Java Programming Quiz

Card1 / 20
Mastered0
Review0
QuestionClick to flip

Given: class CardBoard { Short story = 5; CardBoard go(CardBoard cb) { cb = null; return cb; } public static void main(String[] args) { CardBoard c1 = new CardBoard(); CardBoard c2 = new CardBoard(); CardBoard c3 = c1.go(c2); c1 = null; // do Stuff } } When // doStuff is reached, how many objects are eligible for GC?

AnswerClick to flip back
A
2
💡 Explanation:

At // doStuff, two CardBoard objects are eligible for garbage collection: c1 and the object originally referenced by c1 before go() was called. The go() method sets its local parameter cb to null, but this does not affect the actual c2 object. After c1 = null, the first CardBoard object becomes eligible. c2 remains referenced.

Change Mode