- 3、
NSDictionary *dict = [NSDictionary dictionaryWithObject:@"a value" forKey:@"aKey"];
NSLog(@"%@",[dict objectForKey:@"aKey"]);
[dict release];
控制台中打印的最后一条信息会是:
NSLog(@"%@",[dict objectForKey:@"aKey"]);
[dict release];
控制台中打印的最后一条信息会是:
答案:(C)
对于Objective-C中的方括号“[]”的作用,下列说法错误的是:
答案:(D)
NSString *name = [[NSString alloc]initWithString:@"张三"];
NSLog(@"%d",[name retainCount]);
上述代码打印结果是:
NSLog(@"%d",[name retainCount]);
上述代码打印结果是:
答案:(A)
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)
关于NSSet描述正确的有:
答案:(B)
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)
下面程序段的输出结果是什么:
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)
以下对类的描述不正确的是:
答案:(C)
声明一个返回值为NSArray,并且带两个字符串对象的BLOCK类型变量:
答案:(D)
下面程序段的输出结果是什么:
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)
下列选项中不能正常为emp的name属性赋值的代码有:
答案:(B)
写出下面程序段的输出结果:
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)
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)
下面程序段的输出结果是什么:
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)
-
下面程序段的输出结果是什么:
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
下面程序段的输出结果是什么:
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
查看下列代码,能正确输出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、编译错误,无法执行。