slepax
September 28th, 2000, 09:10 AM
Hey all,
Here is a problem:
I have tree classes, A and B, also known that B extends A.
now...
A a = new A();
B b = (B)a;
The code above throws a ClassCastException, why ?
I've been working for couple of years with C++ and I'm pretty sure this kind of casting is possible, why not in Java ?
If I'm right, and this kind of casting cannot be done, what's the big idea behind OOP in Java ?
Thanks,
Ronen.
Here is a problem:
I have tree classes, A and B, also known that B extends A.
now...
A a = new A();
B b = (B)a;
The code above throws a ClassCastException, why ?
I've been working for couple of years with C++ and I'm pretty sure this kind of casting is possible, why not in Java ?
If I'm right, and this kind of casting cannot be done, what's the big idea behind OOP in Java ?
Thanks,
Ronen.