A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

#import <Foundation/Foundation.h>

@interface Car: NSObject
{

    int _wheels;
    int _speed;

}
- (void)run;
- (void)carBeep;
- (void)setWheels: (int)wheels;
- (int)wheels;
@property int _speed;

@end

@implementation Car

- (void)setWheels: (int)wheels
{
    _wheels = wheels;
}
- (int)wheels
{
    return _wheels;
}
- (void)run
{
    NSLog(@"车子跑起来了");
}

- (void)carBeep
{
    NSLog(@"car 响了");
}
@end

@interface Aodi : Car
- (void)carBeep;
@end
@implementation Aodi
- (void)carBeep
{
    NSLog(@"aodi 响了");
}
@end

@interface Baoma : Car
- (void)carBeep;
@end
@implementation Baoma
- (void)carBeep
{
    NSLog(@"baoma 响了");
}
@end
void leep(Car *c)
{
    [c carBeep];
}

int main()
{
    @autoreleasepool
    {
        Baoma *baoma = [Baoma new];
        leep(baoma);
        Aodi *aodi = [Aodi new];
        leep(aodi);
        //Car *car = [Car new];
        baoma.wheels = 5;
        baoma._speed = 120;

        int wnm = baoma.wheels;
        NSLog(@"baoma 有%d个轮子",wnm);
        //NSLog(@"%d个轮子的车子的速度是%d",car1->wheels,car1->speed);
    }

    return 0;
}


0 个回复

您需要登录后才可以回帖 登录 | 加入黑马