what does the above code do?? does it make one reference variable a and assign it a new Animal object during each iteration. and in the end we have 20 Animal objects added to aList and a refers to the last one and other 19 left without any reference??
posted 8 years ago
Yes, 20 Animal objects are created, and after the loop is done, they are all eligible for garbage collection since they are not referenced.