※ 选择题(共80题,每题1分)
1、OC中布尔(BOOL)类型的变量的值只有:答案:(B)
A、1/0
B、YES/NO
C、true/false
D、1/-1
2、在OC中,类的定义包括两部分(声明与实现),其中实现部分是:答案:(C)
A、@import
B、@interface
C、@implementation
D、@protocol
3、声明一个方法:提供Student对象数组按照学号升序排列的判断条件:答案:(A)
A、-(NSComparisonResult)compareWithNumberForAscendSort:(Student*)otherStudent
B、-(NSInteger)compareWithNumberForAscendSort:(Student*)otherStudent
C、-(BOOL))compareWithNumberForAscendSort:(Student*)otherStudent
D、+(int)compareWithNumberForAscendSort:(Student
4、以下说法不正确的是:答案:(A)
A、nonatomic:提供多线程保护,提高性能,在没有使用多线程的编程中可以选择使用。
B、assign:属性默认值。说明设置器直接进行赋值,针对基础数据类型 (NSInteger,CGFloat)和C数据类型(int, float, double, char)等等。
C、retain:此属性只用于obj-c的对象类型,对参数进行release旧值,再retain新值。
D、copy:此属性只对实现NSCopying协议的对象有效(NSString)。拷贝工作由copy方法执行。
5、OC中的委托最好声明成:答案:(B)
A、retain
B、assign
C、copy
D、readonly
6、使用 Objective-C 语言输出“This is a Objective-Cprogram.”正确的是:答案:(D)
A、NSLog(@"%s",This isa Objective-C program.);
B、NSLog(@"%@",This isa Objective-C program.);
C、NSLog(@"This is aObjective-C program.",%@);
D、NSLog(@"This is a Objective-Cprogram.");
7、NSDictionary *dict =[NSDictionary dictionaryWithObject:@"a value"forKey:@"aKey"];
NSLog(@"%@",[dictobjectForKey:@"aKey"]);
[dictrelease];
控制台中打印的最后一条信息会是:答案:(C)
A、a value
B、aKey : a value
C、崩溃信息
D、a value : aKey
8、Objective-C的代码文件的后缀为:答案:(B)
A、.cpp
B、.m
C、.pl
D、.c
9、-(id)setName:(NSString *)name:(NSString *)sex age:(int)age的方法名是:答案:(C)
A、-(id)setName:(NSString *)name:(NSString *)sex age:(int)age
B、-setName:name :sex age:age
C、setName: : age:
D、setName:name:age:
10、面向对象的特性不包括:答案:(D)
A、封装
B、继承
C、多态
D、构造
11、NSMutableString * str =[[NSMutableString alloc] initWithFormat:@"123"];
NSLog(@"str= %p",str);
[strappendFormat:@"456"];
NSLog(@"str= %p",str);
上面代码对字符串str进行拼接后,2次打印的地址是否相同:答案:(A)
A、相同
B、不同
C、随机打印
D、有时相同,有时不同
12、Objective-C中包含一个自定义的头文件应该使用:答案:(C)
A、#include ""
B、#include<>
C、#import ""
D、#import<>
13、下列哪个选项与@synthesize配合使用:答案:(D)
A、@end
B、@interface
C、@implementation
D、@property
14、以下代码执行后,person对象的retain count是多少:
Person* person = [[Person alloc] init];
[personretain]; [person release];答案:(B)
A、0
B、1
C、2
D、3
15、不会立刻使引用计数器改变的是:答案:(C)
A、release
B、alloc
C、autorelease
D、retain
16、关于类和对象的概念,下列属于对象的是:答案:(C)
A、奥迪A6
B、保龄球
C、世界冠军杨威
D、西红柿
17、NSArray *array = [NSArrayarrayWithObjects:@"one", @"two", @"three",nil];
NSLog(@"%@",[arrayobjectAtIndex:1]);
NSLog(@"%@",[arrayobjectAtIndex:3]);
控制台中打印的最后一条信息会是:答案:(D)
A、one
B、two
C、three
D、崩溃信息
18、NSString *name = [[NSStringalloc]initWithString:@"赵四"];
NSLog(@"%d",[nameretainCount]);
上述代码打印结果是:答案:(A)
A、-1
B、0
C、1
D、2
19、NSArray *array = [NSArrayarrayWithObjects:@"1",@"2",@"3",@"4",@"2",nil];
NSMutableSet*set = [[NSMutableSet alloc]init];
for(NSString*str in array)
{
[setaddObject:str];
}
NSLog(@"%lu",[setcount]);
[setrelease];
控制台打印的结果是:答案:(A)