//
// 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