My main problem is how many object is really created at executing the line
Dozens [] da = new Dozens[3];
And how many object will be eligible for garbage collection at the end of main function
class Dozens {
int[] dz = {1,2,3,4,5,6,7,8,9,10,11,12};
}
public class Eggs {
public static void main(String[] args) {
Dozens [] da = new Dozens[3];
da[0] = new Dozens();
Dozens d = new Dozens();
da[1] = d;
d = null;
da[1] = null;
// do stuff
}
}
After executing
Dozens [] da = new Dozens[3];a single object will be created. After themainmethod is finished, if you don’t create another thread that uses the objects created inmain, all the objects that you created will be available for garbage collecting.