This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Please explain the answer of this question,i could not understand why A1A2A3 is printed instead of only A1 in answers.
for loop will execute below mentioned 4 lines:
a0 = a0.other(); //that means a0 = a1 ... which will print A1 a0 = a0.other(); //that means a0 = a2 ... which will print A2 a0 = a0.other(); //that means a0 = a3 ... which will print A3 a0 = a0.other(); //that means a0 = a1 ... which will print A1
It says which "could" be a result of attempting to compile and run the program.
The program will always print
However in the main method after the call to m1(), we suggest the garbage collector run. So it could run and decide to collect any/all/none of the A objects (with names A1, A2, A3) in which case the finalize method would be called and they would print their name.