前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >何使用派生类指针指向基类,即downcast向下转型

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

作者头像
马克java社区
修改2021-03-29 10:17:51
5670
修改2021-03-29 10:17:51
举报
文章被收录于专栏:java大数据

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

if you want to use derived class pointe

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;

更多请见:https://blog.csdn.net/qq_44639795/article/details/103117238

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档