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.
First casts a B type reference to the A reference type, obtaining an A type reference. This is guaranteed to both compile and run without error (upcasting.) Second, cast the A type reference to the B reference type. This is guaranteed to compile, but may or may not throw an exception based on the actual type of the object (downcasting.) Since the type of the object referred to by b is B, in this case the casting works, and you end up with the same reference you started with (b, a reference of type B pointing to an object of type B.)
All code in my posts, unless a source is explicitly mentioned, is my own.