何使用派生类指针指向基类,即downcast向下转型?

基类指针指向派生类,我们已经很熟了。假如我们想用派生类反过来指向基类,就需要有两个要求:1)马克-to-win:基类指针开始时指向派生类,2)我们还需要清清楚楚的转型一下。


if you want to use derived class pointer
point to base class, there are two requirements:
1) base class pointer is initially the type of the derived class like Animal a2 = new Dog();
2) 马克-to-win:we still need to explicitly cast it like Dog d = (Dog)a2;
。。。。。。。。。。
详情请见:http://www.mark-to-win.com/JavaBeginner/JavaBeginner3_web.html#HowToUseDowncasting
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页