Guys, here is another question whose answer I don't understand, from
Glenn, Mitchell.
OCAJP Oracle Certified Associate
Java SE 8 Programmer Practice Exams (Kindle Locations 11419-11425). Enthuware. Kindle Edition.
Consider the following code:
After what line the MyClass object created at line 1 will be eligible for garbage collection? Select 1 option
A. 2
B. 5
C. 6
D. 7
E. Never till the program ends.
My answer was E but it's apparently C. I answered E because even when x is made to point to a different object, a new one that it, mc still points at the object created at line 1. I thought that by doing
and returning its reference to x we effectively ended up with two references to the same object and removing one would not remove the other one, hope it makes sense.