码迷,mamicode.com
首页 > 其他好文 > 详细

Objective-C的第二课

时间:2014-10-05 23:17:19      阅读:266      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   strong   sp   div   

今天学习了继承, 属性, 多态

 

作业:动物父类, 猫科子类, 狮子孙子类;

#import <Foundation/Foundation.h>

@interface Animal : NSObject

@end    //动物类


#import <Foundation/Foundation.h>

@interface Animal : NSObject

@end    //动物类




#import "Animal.h"

@interface Feline : Animal
- (void)eyes;

- (void)tail;

- (void)flid;

@end    //猫科动物类


#import "Animal.h"

@interface Feline : Animal
- (void)eyes;

- (void)tail;

- (void)flid;

@end    //猫科动物类



#import "Feline.h"

@interface Lion : Feline

- (void)character;

- (void)body;

@end    //狮子类


#import "Lion.h"

@implementation Lion

- (void)character
{
    NSLog(@"%@", @"Lion character fierce and cruel");    //性格凶残
}

- (void)body
{
    NSLog(@"%@", @"Lion A strong");  //身体强壮
}

@end    //狮子类



#import "ViewController.h"
#import "Lion.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    Animal *animal;
    
    Feline *feline;  //定义对象
    feline = [[Feline alloc] init];  //初始化
    [feline flid];  //打印行为
    [feline eyes];
    [feline tail];
    [feline release];
    
    
    Lion *lion;
    lion = [[Lion alloc] init];
    [lion character];
    [lion body];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end

 

Objective-C的第二课

标签:style   blog   color   io   os   ar   strong   sp   div   

原文地址:http://www.cnblogs.com/iOSCain/p/4007455.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!