1. For the following codes segments (You can assume the code is in the proper pl
ID: 3872904 • Letter: 1
Question
1. For the following codes segments (You can assume the code is in the proper place and runs properly):
...
String[] allEmployees = new String[15];
String employeeName = "Bill Gates";
allEmployees[0] = employeeName;
allEmployees = null;
...
After the code is executed, how many references to the array object and the string object exists ? Is either object eligible for garbage collection ?
Two references to the allEmployees array and one reference to the employeeName variable. The employeeName is eligible for garbage collection and the allEmployees array is not.
Two references to the allEmployees array and two references to the employeeName variable. Both are eligible for garbage collection.
NONE of the above
One reference to the allEmployees array and two references to the employeeName variable. The allEmployeesarray is eligible for garbage collection and the employeeName variable is not.
One reference to the allEmployees array and that array has one reference to the string Bill Gates. Neither object is eligible for garbage collection.
Zero references to employeeName variable and one reference to the allEmployees array. The employeeName variable is eligible for garbage collection and the allEmployees array is not.
2. What are the differences between IP-Based virtual hosts compared with Name-Based virtual hosts (Select all that apply) ?
Two references to the allEmployees array and one reference to the employeeName variable. The employeeName is eligible for garbage collection and the allEmployees array is not.
Explanation / Answer
Answer for the 1st question:
4)One reference to the allEmployees array and two references to the employeeName variable. The allEmployeesarray is eligible for garbage collection and the employeeName variable is not.
Explanation:
String employeeName = "Bill Gates";
It will create string in the string constant pool and will have reference to that string constant pool which will be hold by employeeName variable
allEmployees[0] = employeeName;
Here allEmployees[0] will have referenec to that string constant pool where string "Biill Gates" is present.
So total two references for employeeName
and here in the below statement we are assinging null value to the allEmployees variable, so now allEmployees will eligible for garbage collection where employeeName is not eligible for garbage collection
allEmployees = null;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.