main.m
//
// main.m
// 12.19
//
// Created by lanqs on 14/12/19.
// Copyright (c) 2014年 . All rights reserved.
//
#import <Foundation/Foundation.h>
#import "animals.h"
#import "animal.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
/*
编写动物世界中的继承树
动物类具有身高,体重,颜色等特征,进食,行走等动作
编写食肉动物和食草动物两个类,继承自动物类,重写父类的方法
编写老虎,狮子等食肉动物类,找出应该继承的父类,并且重写父类的方法
编写牛羊等食草动物,找出应该继承的父类,并且重写父类的方法
*/
[animal action];
[eatMeat action];
[eatgrass action];
[tiger action];
[lion action];
[cow action];
[sheep action];
}
return 0;
}
animal.h
//
// animal.h
// 12.19
//
// Created by lanqs on 14/12/19.
// Copyright (c) 2014年 . All rights reserved.
//
#import <Foundation/Foundation.h>
@interface animal : NSObject{
CGFloat _height;
CGFloat _weight;
NSString *_color;
}
+ (void)action;
@end
animal.m
//
// animal.m
// 12.19
//
// Created by lanqs on 14/12/19.
// Copyright (c) 2014年 . All rights reserved.
//
#import "animal.h"
@implementation animal
+ (void)action{
NSLog(@"进食,行走");
}
@end
animals.h
//
// animals.h
// 12.19
//
// Created by lanqs on 14/12/19.
// Copyright (c) 2014年 . All rights reserved.
//
#import <Foundation/Foundation.h>
#import "animal.h"
@interface animals : NSObject
@end
@interface eatMeat : animal
@end
@interface eatgrass : animal
@end
@interface tiger : eatMeat
@end
@interface lion : eatMeat
@end
@interface cow : eatgrass
@end@interface sheep : eatgrass
@end
animals.m
//
// animals.m
// 12.19
//
// Created by lanqs on 14/12/19.
// Copyright (c) 2014年 . All rights reserved.
//
#import "animals.h"
@implementation animals
@end
//
@implementation eatMeat
+(void)action{
NSLog(@"吃肉动物");
}
@end
@implementation eatgrass
+(void)action{
NSLog(@"吃肉动物");
}
@end
@implementation tiger
+(void)action{
NSLog(@"老虎");
}
@end
@implementation lion
+(void)action{
NSLog(@"狮子");
}
@end
@implementation cow
+(void)action{
NSLog(@"牛");
}
@end
@implementation sheep
+(void)action{
NSLog(@"羊");
}
@end