All objects need not necessarily be garbage collected. The output will be different in different environment settings. In my system 4 objects were garbage collected. There is no guarentee that all unnecessary objects will be GCed.
So what to do when I get such questions asking for how many objects will be garbage collected considering the above code. I too know that the gc is totally under the control of JVM. Please can anyone give me ideason what to concentrate and on what not to for the scjp 1.4, Garbage collectors topic.