标签:
Animal *animal = nil;
//实例化猫的对象
animal = [Cat new];
[animal eat];
//实例化狗的对象
animal = [Dog new];
[animal eat];
假设 子类 Dog 有一个特有的方法bark
[dog bark];
Animal *an2 = [Dog new];
[(Dog*)an2 bark]; //把父类的指针,强制类型转换
Animal *an3 = [Animal new];
[(Dog*)an3 bark]; //错误的,不能强制转换
标签:
原文地址:http://www.cnblogs.com/iOSxgj/p/5205272.html