黑马程序员技术交流社区

标题: 体会到了面向对象的优势 [打印本页]

作者: 马小平    时间: 2015-11-29 00:00
标题: 体会到了面向对象的优势
#import<Foundation/Foundation.h>

@interface Autobus : NSObject
{
    @public
    int wheels;
    float speed;
}
-(void)run;
-(void)stop;

@end

@implementation Autobus

-(void)run

{
    NSLog(@"汽车运行了。。。,现在速度是%.1f",speed);
}

-(void)stop

{
    NSLog(@"汽车停止了。。。");
}


@end

int main()
{
    Autobus* audi=[Autobus new];
    audi->wheels=4;
    audi->speed=300;
    [audi run];
    [audi stop];
    audi->speed=500;
    [audi run];
    [audi stop];
    Autobus* toyota=[Autobus new];
    toyota->wheels=4;
    toyota->speed=200;
    [toyota run];
    [toyota stop];
    return 0;
}
作者: caizexu    时间: 2015-11-29 09:16
感谢分享




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2