Java; casting base class to derived class

Posted by incrediman on Stack Overflow See other posts from Stack Overflow or by incrediman
Published on 2010-04-03T19:13:14Z Indexed on 2010/04/03 19:23 UTC
Read the original article Hit count: 271

Filed under:
|
|

Why can't I cast a base class instance to a derived class?

For example, if I have a class B which extends a class C, why can't I do this?

B b=(B)(new C());

or this?

C c=new C();
B b=(B)c;

© Stack Overflow or respective owner

Related posts about java

Related posts about casting