AmritP Singh wrote:Thanks Everyone ..
@Mansukhdeep :- i remember the explanation you gave .. Thats was a nice one.
My understanding is :-
Superclass does not know about the subclass, so this code gave ClassCast exception. however i would still like to know if there is a way out like using instanceof keyword , that i could make this work.
i tried instance of operator, but now i am getting a different error as "cannot find symbol"
Here is the updated code :-
You shouldn't be checking if the class Tree is an instance of the class Redwood (it isn't) you need to be checking if an object is an instance of the class Redwood. So what object do you think
you should put in the if statement instead of Tree?