您的位置:首页 > 其它

oc-15-self

2016-03-22 21:03 211 查看
//
//  Person.m
//  OC基础第三天
//
//  Created by apple on 15/10/17.
//
//

#import "Person.h"

@implementation Person
// 让人运动
- (void)sport
{
//    self:自己
//    本质:是1个指针.
//    位置:方法中.

// 在对象方法当中调用类方法
//    1.self在对象方法中,代表当前对象.
//    2.self在类方法中,代表当前类.
//    3.self访问成员变量
//    self->成员变量名.
[self eat];
self->_age = 10;
NSLog(@"%d年龄的这个人运动--对象方法",self->_age);
//
Person *p = [Person new];
p->_age = 10;
[p eat];//等同于上面
}

// 让人吃
- (void)eat
{
NSLog(@"这个人吃东西--对象方法");
}

// 让人运动
+ (void)sport
{
NSLog(@"这个人运动--类方法");
[self eat];
//
[Person eat];//等价于上面
}

// 让人吃
+ (void)eat
{
NSLog(@"这个人吃--类方法");
}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: