| Author |
ClassCastException ??
|
Bram Maes
Ranch Hand
Joined: Sep 27, 2006
Posts: 32
|
|
Hello fellow ranchers, I was busy experimenting a bit the protected access modifier when using inheritance. When I run the following I get a ClassCastException and I don't know why.... Can anyone help me ? Thanks. SuperClass.java : SubClass.java :
|
SCJP 5.0, SCEA part I
|
 |
Petrus Pelser
Ranch Hand
Joined: Feb 20, 2006
Posts: 132
|
|
Originally posted by Bram Maes:
You can't cast an object of a superclass to the type of a subclass. The following would be fine:
|
 |
Bram Maes
Ranch Hand
Joined: Sep 27, 2006
Posts: 32
|
|
Stupid mistake... you're right thanks a lot!
|
 |
Joe Harry
Ranch Hand
Joined: Sep 26, 2006
Posts: 8795
|
|
Hi above, You are casting down the inheritance tree. You will only be able to make it pass the compiler but it melts down at run time. Regards, Jothi Shankar Kumar. S
|
SCJP 1.4, SCWCD 1.4 - Hints for you, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
|
 |
 |
|
|
subject: ClassCastException ??
|
|
|