nerdexam
Oracle

1Z0-851 · Question #134

Given: class Snoochy { Boochy booch; public Snoochy() { booch = new Boochy(this); } } class Boochy { Snoochy snooch; public Boochy(Snoochy s) { snooch = s; } } And the statements: 21. public static…

The correct answer is E. The objects referenced by snooch and booch are eligible for garbage collection. See the full explanation below for the reasoning.

Question

Given: class Snoochy { Boochy booch; public Snoochy() { booch = new Boochy(this); } } class Boochy { Snoochy snooch; public Boochy(Snoochy s) { snooch = s; } } And the statements: 21. public static void main(String[] args) { 22. Snoochy snoog = new Snoochy(); 23. snoog = null; 24. // more code here 25. } Which statement is true about the objects referenced by snoog, snooch, and booch immediately after line 23 executes?

Options

  • ANone of these objects are eligible for garbage collection.
  • BOnly the object referenced by booch is eligible for garbage collection.
  • COnly the object referenced by snoog is eligible for garbage collection.
  • DOnly the object referenced by snooch is eligible for garbage collection.
  • EThe objects referenced by snooch and booch are eligible for garbage collection.

How the community answered

(43 responses)
  • A
    5% (2)
  • B
    12% (5)
  • C
    2% (1)
  • E
    81% (35)

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice