何使用派生类指针指向基类,即downcast向下转型
基类指针指向派生类,我们已经很熟了。假如我们想用派生类反过来指向基类,就需要有两个要求:1)马克-to-win:基类指针开始时指向派生类,2)我们还需要清清楚楚的转型一下。
马克- to-win:马克 java社区:防盗版实名手机尾号: 73203。
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;