This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
In this piece of code, you have only one object eligible for the garbage collection and is the object String "hello world". In the line 5 is justly where the object String "hello world" is eligible for GC because the reference 'a' leave to reference. And in the line 6 both the reference 'a' and the reference 'b' are aiming at the same object "game over". Don't forget that the reference and the object are things different and lives in memory distinct. The reference live in the stack and de object lives in the heap. I hope help you.