posted 17 years ago
This is the kind of exercise that is much easier to solve with a drawing.
The key is to remember that finalize may be call or not. So we are looking for a beginning of 4 printings with several possible endings (all combinations of 0 or 1 of each A1, A2 and A3).
The beginning of the output is well defined. a0 = a0.other() makes a0 point A1 and returns A1, which toString() method is invoked. Then the same A2, A3 and A1 again.
So every answer with a beginning A1A2A3A1 is valid if the end contains no more than one of A1, A2 or A3 in any order.
Does it make sense?