The following is a c# code, in which I have to find out the number of objects(DOG) and reference after the whole code. Initially I calculated it to be 4 objects and 8 references. But after seeing this question Garbage collector test ,(which says that garbage collector runs only when the system has low memory and other similar causes) I doubt if the no of objects should be 6?. The below question says nothing about the memory obtained by the program.
So my question is if I ever get this type of question what should be my answer(4, 6 or should I say it would depend on the memory)?
Dog rover = new Dog();
rover.Breed = “Greyhound”;
Dog rinTinTin = new Dog();
Dog fido = new Dog();
Dog quentin = fido;
Dog spot = new Dog();
spot.Breed = “Dachshund”;
spot = rover;
Dog lucky = new Dog();
lucky.Breed = “Beagle”;
Dog charlie = fido;
fido = rover;
rinTinTin = lucky;
Dog laverne = new Dog();
laverne.Breed = “pug”;
charlie = laverne;
lucky = rinTinTin;
// No of objects and reference at this point?(DOG objects not considering the string objects)
Hoping this question is not stupid.