您的位置:首页 > 其它

2015.7.9 OC学习第三天

2015-07-09 10:26 357 查看
1.成员变量属于实例变量的一部分,所有的指针变量都是实例变量
2.OC和UI中只要继承NSObject的类,统称为model(模型)类
3.OC中没有多继承,协议是间接实现多继承的方式
4.继承中子类继承父类的所有东西,所以不能用@class 必须用import

people.h
#import <Foundation/Foundation.h>

@interface People : NSObject
{
NSString *_name;
NSString *_sex;
NSInteger _age;
}

- (void)eat;


people.m

- (void)eat
{
NSLog(@"吃食物");
NSLog(@"self = %@", self);

}
student.h
@interface Student : People
{
NSString *_school;
NSInteger _number;
}

@end
student.m
- (void)eat
{
NSLog(@"吃饭"); //重写父类的方法,不需要再次声明
}


main.m
Student *student = [[Student alloc]init];
[student eat];

NSLog(@"student = %@", student);


输出
2015-07-09 10:23:37.423 20150709 OC[4754:354107] 吃饭
2015-07-09 10:23:37.424 20150709 OC[4754:354107] student = <Student: 0x1001110e0>
Program ended with exit code: 0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: