标签:style blog io ar color 使用 sp on div
A.对象的多种形态
1 2 #import <Foundation/Foundation.h> 3 4 @interface Animal : NSObject 5 - (void) eat; 6 @end 7 8 @interface Dog : Animal 9 - (void) run; 10 @end 11 12 @interface Cat : Animal 13 14 @end 15 16 17 @implementation Animal 18 - (void) eat 19 { 20 NSLog(@"吃东西---"); 21 } 22 23 @end 24 25 @implementation Dog 26 - (void) eat 27 { 28 NSLog(@"狗狗吃东西"); 29 } 30 31 - (void) run 32 { 33 NSLog(@"狗狗跑起来了"); 34 } 35 @end 36 37 @implementation Cat 38 39 - (void) eat 40 { 41 NSLog(@"猫猫吃东西"); 42 } 43 44 @end 45 46 void feed(Animal *animal) 47 { 48 NSLog(@"开始喂动物"); 49 [animal eat]; 50 } 51 52 53 int main() 54 { 55 Animal *a = [Dog new]; 56 [a eat]; 57 Animal *c = [Cat new]; 58 [c eat]; 59 60 feed(a); 61 feed(c); 62 63 Dog *dog = (Dog *)a; 64 [dog run]; 65 66 return 0; 67 }
标签:style blog io ar color 使用 sp on div
原文地址:http://www.cnblogs.com/hellovoidworld/p/4119352.html