oc-04-类的声明和实现

//main.m
//10-【掌握】类的声明和实现
//.h为类的声明,.m为类的实现,+表示类方法静态方法,-表示对象方法。.h文件中的方法都是public不能更改的。变量3中访问域:public,protected(子类),private(本类)。
#import <Foundation/Foundation.h>

//声明类
@interface Person : NSObject(父类名)
{
    //声明属性变量的时候 前面一定要加下划线.
    NSString * _name;
    int _age;
    float _weight;
}
//声明方法
- (void)eat;
- (void)run;
+ (void)breath;
@end



//对人类 做一个实现类  要实现哪个类 就在 @implementation 后面 放哪个类的类名.
@implementation Person
//实现方法
- (void)eat{
    NSLog(@"吃吃吃吃");
}
- (void)run{
    NSLog(@"跑跑跑");
}
+ (void)breath{
    NSLog(@"xxixixixix");
}
@end



int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // insert code here...
        NSLog(@"Hello, World!");
    }
    return 0;
}
原文地址:https://www.cnblogs.com/yaowen/p/5305524.html