posted 18 years ago
1. This code snippet has few syntax issues:
x = new Double(i+j).........should end with ";"
int a = x.intvalue();.......it is intValue();
and the print statement should be...System.out.println("a = "+ a);
2. Since
x = new Double(i+j);
is in the loop, every loop iteration creates a new Double object. At the end of the loop, what remains in x is the last Double object created (where i will have the max value possible with the outer loop (4), j will have the max value possible with the inner loop (2). Thus, your program will output "a = 6".
3. Now, since you mention the question is related to GC, the question, I think, can't be just "what is the output?". It may be something related to the fact that each time you go through the loop, you loose the reference to the Double object created during the previous iteration - thus making them possible for GC. All in all you will have 15 Double objects that won't have any reference at the end of the loop, and they will all be eligable for GC.
Hope this helps.