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.
I suppose one reason why you probably find it confusing is that it won't work. Line 9 creates a new Tree object, and immediately casts it to a Redwood object. It then passes is to a method that wants a Tree object.
This will compile - you're casting a Tree reference to a Redwood reference, and because that in theory might work the compiler allows it. The method call is fine as well. But you'll get a ClassCastException as soon as you run that line, because the new Tree object is not a Redwood.
By the way, if you're quoting code you got from somewhere else, can you tell us where it comes from, please?
this code will compile correctly but i will give run time exception. because when you try to type cast sub-class object to super class object it's ok(compile and run both ok) but if you type cast super class object to sub-class
object in that case compile ok but it will give you run time exception.