- 3、
NSDictionary *dict = [NSDictionary dictionaryWithObject:@"a value" forKey:@"aKey"];
NSLog(@"%@",[dict objectForKey:@"aKey"]);
[dict release];
控制台中打印的最后一条信息会是:
NSLog(@"%@",[dict objectForKey:@"aKey"]);
[dict release];
控制台中打印的最后一条信息会是:
答案:(C)
- A、a value
- B、aKey : a value
- C、崩溃信息
- D、a value : aKey
22、
对于Objective-C中的方括号“[]”的作用,下列说法错误的是:
答案:(D)
- A、用于通知某个对象该做什么
- B、方括号内第一项是对象,其余部分是你需要对象执行的操作
- C、在Objective-C中通知对象执行某种操作,称为发送消息.(也叫调用方法)
- D、方括号中可以为空
26、
NSString *name = [[NSString alloc]initWithString:@"张三"];
NSLog(@"%d",[name retainCount]);
上述代码打印结果是:
NSLog(@"%d",[name retainCount]);
上述代码打印结果是:
答案:(A)
- A、-1
- B、0
- C、1
- D、2
30、
NSArray *array = [NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"2", nil];
NSMutableSet *set = [[NSMutableSet alloc]init];
for(NSString *str in array)
{
[set addObject:str];
}
NSLog(@"%lu",[set count]);
[set release];
控制台打印的结果是:
NSMutableSet *set = [[NSMutableSet alloc]init];
for(NSString *str in array)
{
[set addObject:str];
}
NSLog(@"%lu",[set count]);
[set release];
控制台打印的结果是:
答案:(A)
- A、4
- B、5
- C、6
- D、7
31、
关于NSSet描述正确的有:
答案:(B)
- A、NSSet可以存放任何数据类型的数据。
- B、NSSet存放数据是无序的。
- C、NSSet可以通过下标获取数据。
- D、NSSet存放的数据是有序的。
37、
现要求声明一个集合,并将字符串添加到集合中,编写了如下代码,其中错误的是第几行:
NSString * aString = [[NSString alloc] initWithString:@"iLanou"]; (1)
[aString autorelease]; (2)
NSArray * arr = [NSArray array]; (3)
[arr addObject:aString]; (4)
NSLog(@"string = %lu",[aString retainCount]);
NSString * aString = [[NSString alloc] initWithString:@"iLanou"]; (1)
[aString autorelease]; (2)
NSArray * arr = [NSArray array]; (3)
[arr addObject:aString]; (4)
NSLog(@"string = %lu",[aString retainCount]);
答案:(C)
- A、(1)
- B、(2)
- C、(3)
39、
下面程序段的输出结果是什么:
NSArray * arr1 = [[NSArray alloc] initWithObjects:@"1",@"2",@"3", nil];
NSString *str;
str = [arr1 objectAtIndex:2];
NSLog(@"%@",str);
NSArray * arr1 = [[NSArray alloc] initWithObjects:@"1",@"2",@"3", nil];
NSString *str;
str = [arr1 objectAtIndex:2];
NSLog(@"%@",str);
答案:(C)
- A、1
- B、2
- C、3
- D、程序崩溃
46、
以下对类的描述不正确的是:
答案:(C)
- A、类的接口部分可以包含实例变量、属性和方法
- B、可以把声明和实现都放到.h文件中
- C、一对文件(Person.h Person.m)只能定义一个类
- D、类比较抽象,对象比较具体
53、
声明一个返回值为NSArray,并且带两个字符串对象的BLOCK类型变量:
答案:(D)
- A、NSArray (*aBlock)(NSString * str,NSString *str2)
- B、NSArray ^(*aBlock)(NSString * str,NSString *str2)
- C、NSArray (^aBlock)(NSString * str,NSString *str2)
- D、NSArray *(^aBlock)(NSString * str,NSString *str2)
66、
下面程序段的输出结果是什么:
NSString * aString = [[NSString alloc] initWithString:@"hehe"];
[aString autorelease];
NSMutableArray *arr = [NSMutableArray array];
[arr addObject:aString];
NSLog(@"string = %d",[aString retainCount]);
NSString * aString = [[NSString alloc] initWithString:@"hehe"];
[aString autorelease];
NSMutableArray *arr = [NSMutableArray array];
[arr addObject:aString];
NSLog(@"string = %d",[aString retainCount]);
答案:(A)
- A、string = -1
- B、string = 0
- C、string = 1
- D、string = 2
68、
下列选项中不能正常为emp的name属性赋值的代码有:
答案:(B)
- A、emp.name=@"李嘉诚";
- B、emp->name=@"李开复";
- C、[emp setValue:@"柳传志" forKey:@"name"];
- D、[emp setName:@"黄光裕”];
69、
写出下面程序段的输出结果:
NSString * aString = [[NSString alloc] initWithString:@"123"];
[aString autorelease];
NSMutableArray * arr = [NSMutableArray array];
[arr addObject:aString];
NSLog(@"string = %lu",[aString retainCount]);
NSString * aString = [[NSString alloc] initWithString:@"123"];
[aString autorelease];
NSMutableArray * arr = [NSMutableArray array];
[arr addObject:aString];
NSLog(@"string = %lu",[aString retainCount]);
答案:(C)
- A、1
- B、0
- C、整型最大值
- D、2
70、
NSMutableDictionary * dic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"1",@"2",@"2",@"3",@"3",@"4", nil];
NSArray *arr = [[NSArray alloc] initWithArray:[dic allKeys]];
NSString *str = [[NSString alloc] initWithFormat:[arr objectAtIndex:0],[arr objectAtIndex:1],[arr objectAtIndex:2]];
NSLog(@"%@",str);
结果是:
NSArray *arr = [[NSArray alloc] initWithArray:[dic allKeys]];
NSString *str = [[NSString alloc] initWithFormat:[arr objectAtIndex:0],[arr objectAtIndex:1],[arr objectAtIndex:2]];
NSLog(@"%@",str);
结果是:
答案:(C)
- A、123
- B、234
- C、2
- D、3
71、
下面程序段的输出结果是什么:
NSMutableDictionary * dic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"1",@"2",@"1",@"3",@"1",@"4", nil];
NSArray *arr1 = [[NSArray alloc] initWithArray:[dic allKeys]];
NSArray *arr2 = [[NSArray alloc] initWithArray:[dic allValues]];
NSMutableDictionary *dic2 = [[NSMutableDictionary alloc] initWithObjects:arr1 forKeys:arr2];
NSLog(@"%@",dic2);
NSMutableDictionary * dic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"1",@"2",@"1",@"3",@"1",@"4", nil];
NSArray *arr1 = [[NSArray alloc] initWithArray:[dic allKeys]];
NSArray *arr2 = [[NSArray alloc] initWithArray:[dic allValues]];
NSMutableDictionary *dic2 = [[NSMutableDictionary alloc] initWithObjects:arr1 forKeys:arr2];
NSLog(@"%@",dic2);
答案:(C)
- A、1=2 1=3 1=4
- B、2=1 3=1 4=1
- C、1=4
- D、4=1
- 76、
下面程序段的输出结果是什么:
NSMutableDictionary * dic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"1",@"2",@"2",@"3",@"3",@"4", nil];
[dic setObject:@"1" forKey:@"3"];
[dic removeObjectForKey:@"1"];
NSLog(@"%@",dic);答案:(C)
- A、1=3 2=3 3=4
- B、1=2 1=3 3=4
- C、2=1 3=1 4=3
- D、3=1 3=2 4=3
78、
下面程序段的输出结果是什么:
NSString * aString = [[NSString alloc] initWithFormat:@"123"];
NSLog(@"%d",aString.retainCount);
aString = @"456";
NSLog(@"%d",aString.retainCount);
[aString release];
aString = @"789";
NSLog(@"%d",aString.retainCount);
NSString * aString = [[NSString alloc] initWithFormat:@"123"];
NSLog(@"%d",aString.retainCount);
aString = @"456";
NSLog(@"%d",aString.retainCount);
[aString release];
aString = @"789";
NSLog(@"%d",aString.retainCount);
答案:(D)
- A、1,2,1
- B、1,1,0
- C、1,-1,0
- D、1,-1,-1
80、
查看下列代码,能正确输出number的选项是:
@interface MyClass : NSObject
{
int number;
}
+(void) printNumber;
@end
@implementation MyClass
+(void) printNumber
{
number =10;
NSLog(@""%d"",number);
}
@end
@interface MyClass : NSObject
{
int number;
}
+(void) printNumber;
@end
@implementation MyClass
+(void) printNumber
{
number =10;
NSLog(@""%d"",number);
}
@end
答案:(D)
- A、[MyClass printNumber];
- B、MyClass * obj = [[MyClass alloc] init]; [obj printNumber];
- C、printNumber();
- D、编译错误,无法执行。