OC练习题 2

发布时间 : 星期四 文章OC练习题 2更新完毕开始阅读

26、

OC中与alloc相反的方法是:

A、release B、retain C、dealloc D、free 27、

用哪个关键字定义协议中必须实现的方法:

A、@optional B、@protected C、@private D、不用写关键字 28、

下面哪些选项是属性的正确声明方式:

A、@property(nonatomic,retain)NSString myString; B、@property(nonatomic,assign)NSString * myString; C、@property(nonatomic,assign)int mynumber; D、@property(nonatomic,retain)int mynumber; 29、

对于Objective-C中的方括号“[]”的作用,下列说法错误的是:

A、用于通知某个对象该做什么

B、方括号内第一项是对象,其余部分是你需要对象执行的操作

C、在Objective-C中通知对象执行某种操作,称为发送消息.(也叫调用方法) D、方括号中可以为空 30、

以下代码执行后,person对象的retain count是多少:Person * person = [[Person alloc] init];[person retain]; [person release]; A、0 B、1 C、2 D、3 31、

创建对象时,对象的内存和指向对象的指针分别分配在哪里:

A、堆区,栈区 B、常量区,堆区 C、全局区,栈区 D、栈区,堆区 32、

协议与委托的描述不正确的是:

A、委托是iOS的一种设计模式 B、协议里的方法默认是必须实现的

C、类接受了多个协议,这些协议写在父类后面的<>内,多个协议之间用“、”隔开

D、定义协议使用@protocol关键字 33、

类何时调用dealloc方法:

A、[property release]后 B、[instance release]后 C、[super dealloc]时 D、当引用计数为0时. 34、

NSDateFormatter * formatter = [[NSDateFormatter alloc] init]; [formatter setAMSymbol:@\setDateFormat:@\[formatter stringFromDate:[NSDate date]]; NSLog(@\打印结果是:

A、2012-05-31 17:45:04 PM B、12-05-31 17:45:04 C、2012-05-31 17:45:04 D、12-05-31 05:45:04 PM 35、

NSRange的成员变量有:

A、location,length

B、width,height C、location,height D、length,width 36、

现有自定义类Student,下列选项中Student类的便利构造器编写正确的是:

A、-(id) initWithName:(NSString *) newName{ Student * stu = [[Student alloc] init]; stu.Name = newName; return stu;}

B、+(id) studentWithName:(NSString *) newName{ Student * stu = [[Student alloc] init]; stu.Name = newName; return stu;}

C、+(id) studentWithName:(NSString *) newName{ Student * stu = [[Student alloc] init]; stu.Name = newName; [stu release]; return stu;}

D、+(id) studentWithName:(NSString *) newName{ Student * stu = [[Student alloc] init]; stu.Name = newName; [stu autorelease]; return stu;} 37、

自定义一个Person类,下面哪个选项是规范的便利构造器声明方式:

A、-(id)personWithName:(NSString *)theName; B、-(id)personwithName:(NSString *)theName; C、+(id)personwithName:(NSString *)theName; D、+(id)personWithName:(NSString *)theName;

联系合同范文客服:xxxxx#qq.com(#替换为@)