This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
Hi, That's right, a Tree cannot be a Redwood; although, a Redwood can be a Tree.
Not sure where "line 10" is in your example... but see if this clears is up for you. It's all about the references.
Tree t = new Tree( ) can never be downcast to a Redwood.
Tree tr = new Redwood( ) can be downcast to a Redwood.
Remember, the object never changes, but it's "references" do. And object is an object is an object. A Tree will always be a Tree. A Redwood will always be a Redwood. You can't change that. You can only change the references.
Hope I'm not wrong, but that's how I see it.
Joined: Feb 01, 2007
Thanks for the explanation. that cleared my query on references