java中的向下转型

1.父类对象可以强制转换为子类对象,但是前提是此父类对象为子类对象实例化的结果。

e.g. Fruit fruit=new Apple();

     Apple a=(Apple)fruit;//ok

e.g. 假设Apple类继承于Fruit类,

     Object fruit=new Fruit();

     Object apple=(Apple)fruit;//wrong

2.子类的实例向父类转型是为了实现多态。

原文地址:https://www.cnblogs.com/heiming/p/5769725.html