--------------<br />Prashant<br />SCJP-91%
--------------<br />Prashant<br />SCJP-91%
a beginner in java
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
a beginner in java
SCJP2. Please Indent your code using UBB Code
a beginner in java
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
giddee up
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
For the following question...
class I {
private String name;
public String toString() {return name;}
public I(String s) {name = s;}
}
class J {
private static void m1(I[] a1) {
a1 = null;
}
public static void main (String[] args) {
I[] a1 = new I[3]; // 1
a1[0] = new I("A"); // 2
a1[1] = new I("B"); // 3
a1[2] = new I("C"); // 4
m1(a1);
for (int i = 0; i < a1.length; i++) {
System.out.print(a1[i]);
}
}
}
After method m1 returns the objects on which of the following lines are eligible for garbage collection?
a. 1
b. 2
c. 3
d. 4
e. None of the above.
f. Compiler error.
g. Run time error.
h. None of the above.
I selected e which is correct. My reasoning was,
when method m1 is called, a copy of the array a1 is passed and set to null. But the original array a1 is still not null so its not eligible for garbage collection.
Is this line of reasoning okay ?
Thanks
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
giddee up
a beginner in java
Blood pressure normal? What do I change to get "magnificent"? Maybe this tiny ad?
Master Gardener Program
https://coderanch.com/t/771761/Master-Gardener-Program
|