dear prasanna.. take a heavy breadth...and read on..
your evaluation of the expression that
>if( tree instanceof Tree )
>becomes
>if( Pine instanceof Tree )
>which evaluates to false ?
is wrong in some good sense.
Tree
/\
/ \
pine oak
read on...
now the code creates a pine object.
assigns a reference to the object to an tree reference
Tree tree= new Pine();
and consider: tree instanceof pine
and have you wondered what does this all means?
it means that the pine object can act not only as a pine but also as a tree object.since it inherits all the features of tree.
this is known as
polymorphism in object oriented programming.
i.e an object can exhibit many(poly) forms.
thus and pine is an instance of tree therefore
tree instanceof pine is true.
and ofcourse
tree is an instanceof Tree
therefore tree instanceof Tree is true
but u see...
tree instanceof oak is not true why?
because tree object cannot exhibit the same behavior as that of an oak. getting my point? oak and pine are two diffrent classes and hence diffrent behaviour.
we say x instanceof y whenever:
x can exhibit all behaviour as that of y.
-good luck
and do take care.
bye