A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© Yip-Jun 中级黑马   /  2015-11-30 23:57  /  1935 人查看  /  13 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 Yip-Jun 于 2015-12-1 00:00 编辑

1, self在类方法和对象方法使用的区别?
/*
self 作用在类方法中,代表的时当前类,只有类名才能调用类方法
self 作用在对象方法中,代表调用者,只有对象才能调用对象方法
*/

2,变量的作用域有哪四种?
/*
@public    公开的--->作用与所有的类
@protected 受保护的--->作用于当前类,子类(派生类)
@private   私有的--->作用于当前类
@package   框架级别的--->作用于框架级别的
*/

3,oc中如何表示继承?写代码说明;(比如Student继承Person)
/*
@interface  Person : NSObject

@end
@implementation Person

@end
@interface  Student : Person

@end
@implementation Student

@end
*/

4,继承体系中,方法调用的顺序是什么?
/*
在自己类中寻找
如果没有,去父类中寻找
如果没有,去父类的父类中寻找
如果没有,就往上找,直到直到基类(NSObiect)
如果基类也没有就报错
*/

5、有一个学生,学习累了的时候,就用电脑玩会游戏;
要求: 当学习到第三次或者第五次的时候,就用电脑玩游戏放松一下;

设计一个学生类Student;
有一个学习的方法:study
有一个学习的次数:time

有一个电脑类:Computer
电脑有个玩游戏的方法playGames;
要求:在类中加入私有变量和私有方法来实现。


#import <Foundation/Foundation.h>
@interface Computer : NSObject
-(void)playGames:(int)time;
@end

#import "Computer.h"
@implementation Computer
-(void)playGames:(int)time{
    NSLog(@"学生学习了 %d 次后,玩游戏休息",time);
}
@end

#import <Foundation/Foundation.h>
#import "Computer.h"
@interface Student : NSObject
{
//    @public
    NSString *_name;
    int _age;
       int _time;
    int _studyTime;
//    @private
//    Computer *_computer;
}
-(void)studyTime;
@end

#import "Student.h"
@implementation Student
-(void)studyTime{
    self -> _time = 10;
    for (int i =1; i<_time; i++) {
         _studyTime++;
        if (i ==5 ||i ==3) {
            [self relax];
        } else {
            continue;
        }
    }
}

-(void)relax{
    [[Computer new] playGames:_studyTime];
}
@end

#import <Foundation/Foundation.h>
#import "Student.h"
int main(int argc, const char * argv[]) {
    @autoreleasepool {
//        [Student study:10];
        Student *student =[Student new];
        [student studyTime];
        int time = 0;
//        Computer *computer = [Computer new];
    }
    return 0;
}



13 个回复

倒序浏览
学习了,多谢了。
回复 使用道具 举报
我们OC马上也要开课了,谢谢分享啊
回复 使用道具 举报
                 谢谢分享
回复 使用道具 举报
强烈支持楼主ing
回复 使用道具 举报
过几天我班也要OC阶段学习了,收藏以后看,谢谢楼主分享!
回复 使用道具 举报
学习了,多谢了。
回复 使用道具 举报
hei军 中级黑马 2015-12-1 14:28:04
8#
支持楼主,现在有好多困惑的地方
回复 使用道具 举报
chensc 金牌黑马 2015-12-1 20:58:53
9#
学习学习!
回复 使用道具 举报
楼主题目在哪里找的啊,我也想找一点题目做一下,分享一下
回复 使用道具 举报
赞。看着不错。
回复 使用道具 举报
我们OC马上也要开课了,谢谢分享啊
回复 使用道具 举报
yako 中级黑马 2015-12-1 22:56:21
13#
后天开课,可以先看看了,多谢!
回复 使用道具 举报
还有代码,感谢
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马