Exam Permalink:
https://www.jobilize.com/java-certification-questions
Question Permalink:
https://www.jobilize.com/what-makes-java-object-eligible-for-garbage-collection
Question 96 / 297:  What can be inserted at // insert code here, to make object created at line 5 eligible for garbage collection?
public static void main(String[] args) {

Integer[] arr = new Integer[3];

arr[0] = new Integer("3"); // Line 5

Integer x = arr[0];

// insert code here

}

A  arr[0] = null;
B  x = null;
C  arr = null; x = new Integer(450);
D  Any of the above
<< First < Previous Next > Last >>
Explanation:

There are two references to the object created at line 5, a[0] and x.

Nulling only "arr" or "arr[0]" or "x", or making them point to other objects, is not enough.

We need to detach all the references to this object.

So, to make the object eligible for garbage collection, we can either :

1) set "arr" to null or to other object and set "x" to null or other object

2) or set "arr[0]" to null or other object and set "x" to null to other object

Exam Home Page
https://www.jobilize.com/java-certification-questions

Oracle Certified Professional Java Programmer

Author:

Access: Public Instant Grading

Ask
Madison Christian
Start Exam
Copy and paste the following HTML code into your website or blog.
<iframe src="https://www.jobilize.com/embed/java-certification-questions" width="600" height="600" frameborder="0" marginwidth="0" marginheight="0" scrolling="yes" style="border:1px solid #CCC; border-width:1px 1px 0; margin-bottom:5px" allowfullscreen webkitallowfullscreen mozallowfullscreen> </iframe>