posted 19 years ago
The answer should be a, c , d, e. Explain below:
in method m1(), it created three local variable a1,a2,a3. a0 points to the same object as a3 first. when you ran the for loop a0 will point to in the order of object A1,A2,A3,A1. so the output for sure will have A1A2A3A1. afer m1() returns, those local reference variable a1,a2,a3,a0 expired, so the objects they point to are eligible for collection. then run System.gc(), Remember running System.gc() just requires JVM to collect gargabe. it is not guranteed whether it will collect or not and in which order it will collect. Although there are three objects eligible to collect, it may collect one or two(answer c) or three ( answer d, e) or none( answer a) of them.