Hi All,
I have executed the below Code
public class Redwood extends Tree {
public static void main(
String[] args) {
new Redwood().go();
}
void go() {
go2(new Tree(), new Redwood());
go2((Redwood) new Tree(), new Redwood());
}
void go2(Tree t1, Redwood r1) {
Redwood r2 = (Redwood)t1; //Line 10
Tree t2 = (Tree)r1;
}
}
class Tree { }
I am getting ClassCastException at Lien 10 saying that Tree cannot be cast to Redwood, But as I understand Redwood is a subclass of Tree so it is downcast to Tree
Can somebody explain why this downcast is throwing Classcast Exception
Thanks
Srinivas