类别

来源:互联网 发布:网络购物案列分析 编辑:程序博客网 时间:2024/04/28 05:06
创建一个类student

该类有十个方法,利用分类的形式,将这十个方法分类别进行管理,并实现调用


#import <Foundation/Foundation.h>

@interface Student : NSObject
@property(nonatomic,retain)NSString *name;

@end


@interface Student (study)
-(void)studyMath;
-(void)studyEnglish;
-(void)studyChinese;

@end

@interface Student (eat)
-(void)eatApple;
-(void)eatBanana;
-(void)eatPear;
@end

@interface Student (play)
-(void)playSoccer;
-(void)playBasketball;
-(void)playGuitar;
-(void)playPiano;
@end


#import "Student.h"


@implementation Student


-(void)studyMath

{

    NSLog(@"studyMath");

}

-(void)studyEnglish

{

    NSLog(@"studyEnglish");

}

-(void)studyChinese

{

    NSLog(@"studyChinese");

}




-(void)eatApple

{

    NSLog(@"eatApple");

}

-(void)eatBanana

{

    NSLog(@"eatBanana");

}

-(void)eatPear

{

    NSLog(@"eatPear");

}




-(void)playSoccer

{

    NSLog(@"playSoccer");

}

-(void)playBasketball

{

    NSLog(@"playBasketball");

}

-(void)playGuitar

{

    NSLog(@"playGuitar");

}

-(void)playPiano

{

    NSLog(@"playPiano");

}

@end



#import <Foundation/Foundation.h>

#import "Student.h"

int main(int argc,const char * argv[])

{


    @autoreleasepool {

        Student *stu=[[Studentalloc]init];

        [stu setName:@"Tiffany"];

        [stu studyMath];

        [stu studyEnglish];

        [stu studyChinese];

        [stu eatApple];

        [stu eatBanana];

        [stu eatPear];

        [stu playSoccer];

        [stu playBasketball];

        [stu playGuitar];

        [stu playPiano];

        NSLog(@"%@",stu);

        

        

        

    }

    return 0;

}



0 0
原创粉丝点击