何使用派生類指針指向基類,即downcast向下轉(zhuǎn)型
基類指針指向派生類,我們已經(jīng)很熟了。假如我們想用派生類反過來指向基類,就需要有兩個要求:1)馬克-to-win:基類指針開始時指向派生類,2)我們還需要清清楚楚的轉(zhuǎn)型一下。
馬克- to-win:馬克 java社區(qū):防盜版實名手機(jī)尾號: 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;