class Animal {}
class Cat extends Animal {}
class Dog extends Animal {}
public class GarbageCollection
{
public static void main(String[] args)
{
Animal a1 = new Cat();
Animal a2 = new Dog();
Animal a3 = a1;
a1 = null;
Animal a4 = a1;
Animal a5 = a2;
a1 = a2;
a2 = a4;
a5 = null;
a3 = a1;
// Here
}
}
When that code reaches the comment "Here" how many objects will be eligible for garbage collection?
This is the example taken from Corey's Blog.Only the cat object will be eligible for garbage collection..........? There are some other variables a4,a2,a5 which have null values in the last stage.Those variables will also be eligible for garbage collection,na?