@fiy-fish
2015-07-18T19:32:34.000000Z
字数 722
阅读 1358
Objective-c
// main.m
// day06-04-多态
//
// Created by Aaron on 15/7/8.
// Copyright (c) 2015年 Aaron. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Dog.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
Dog *d = [[Dog alloc] init];
[d show];
}
return 0;
}
#import <Foundation/Foundation.h>
@interface Animal : NSObject
{
@private
NSString *_name;
}
-(void)showName;
@end
#import "Animal.h"
@implementation Animal
-(instancetype)init
{
if(self =[super init])
{
_name = @"xxx";
}
return self;
}
//-(void)setName:(NSString *)name
//{
// _name = name;
//}
-(NSString *)name
{
return _name;
}
-(void)showName
{
NSLog(@"%@",[self name]);
}
@end
#import "Animal.h"
@interface Dog : Animal
-(void)show;
@end
#import "Dog.h"
@implementation Dog
-(void)show
{
NSLog(@"jsahdak");
[super showName];
}
@end