Upwork/oDesk Cocoa programming for Mac OS X 10.5 Test



1. What is true regarding notifications?
Answers:
• They can be dispatched to only one object
• The object posting the notification does not even have to know whether the observer exists
• An object may receive any message you like from the notification center, not just the predefined delegate method
• All of the above
• None of the above

2. What method should be called before you are able to draw in the drawRect: method of a view?
Answers:
• None
• lockFocus
• lockView
• prepareDrawing
• None of the above
3. Is it correct to have sibling views overlapping?
Answers:
• Yes
• No
4. In a typical Cocoa application, do you have to manage your runloop yourself?
Answers:
• Yes
• No
5. In which language is Cocoa written?
Answers:
• C
• Objective-C
• C++
• Java
• Ruby
6. Can an object be the delegate of multiple objects?
Answers:
• Yes
• No
7. Is it mandatory to create an NSAutoreleasePool in a Cocoa application?
Answers:
• Yes
• No
8. What kind of memory management mechanisms can Cocoa uses?
Answers:
• Garbage collection
• Reference counting
• Manual memory management
• None of the above
9. Which of the following retrieves the application main bundle?
Answers:
• [NSBundle mainBundle]
• [NSApplication mainBundle]
• [NSApp mainBundle]
• None of the above
10. Can you use NSLock on a POSIX mutex?
Answers:
• Yes
• No
11. If you spawn a thread with POSIX thread api, will Cocoa be notified?
Answers:
• Yes
• No
12. Which of the following creates an autoreleased array?
Answers:
• [NSMutableArray array];
• [NSMutableArray new];
• [[NSMutableArray alloc] init];
13. What class should be used to load resources?
Answers:
• NSResource
• NSApplication
• NSBundle
• NSFile
• None of the above
14. Can an object marked for autorelease be retained?
Answers:
• Yes
• No
15. What is a notification?
Answers:
• A user event
• A special message type used within the kernel
• An object that encapsulates information about an event
• None of the above
16. Fill the blank.

NSView : <> : NSObject
Answers:
• NSWindow
• NSResponder
• NSResponder : NSWindow
• NSRootView
• NSRoot
17. If you call interpretKeyEvents:, which of the following method is likely to be called?
Answers:
• collectEvent:
• dispatchEvent:
• sendEvent:
• insertText:
• None of the above
18. Where is the (0,0) coordinate located on the screen?
Answers:
• top-left
• top-right
• bottom-left
• bottom-right
• center
19. What method should be called before you are able to draw outside the drawRect: method of a view?
Answers:
• None
• lockView
• lockFocus
• prepareView
• None of the above
20. What will be the output of the following code?

NSRect rect = NSMakeRect(0, 0, 10, 10);
NSRect *rect2 = malloc(sizeof(*rect2));
if(!rect2) {
    NSLog(@"Not enough memory.");
    exit(EXIT_FAILURE);
}

*rect2 = rect;

printf("%d\n", rect.size.width);
Answers:
• 0
• 10
• RUNTIME ERROR
• COMPILATION ERROR
• None of the above
21. Can NSBundle be used to load Java code?
Answers:
• Yes
• No
22. Under Mac OS X 10.5, CGRect, CGSize and CGPoint have the same structure as NSRect, NSSize and NSPoint respectively. Is it true?
Answers:
• Yes
• No
23. What is an observer?
Answers:
• An object that implements the NSObserver protocol
• An object that sends a notification
• An object that receives ALL notifications
• An object registered with the notification center
• None of the above
24. Does Cocoa support 64bits?
Answers:
• Yes
• No
25. Why is CGFloat recommenced to be used instead of float?
Answers:
• They are the same; so it's done only to make the code look nicer.
• CGFloat is a special structure used to do arbitrary number computation.
• For 64bit compatibility.
• None of the above
26. Can resources be localized?
Answers:
• Yes
• No
27. Fill the blank.

NSMutableArray : <> : NSObject
Answers:
• NSSet
• NSCollection
• NSArray
• NSContainer
• NSMovableArray
28. What is NSRect?
Answers:
• A class
• An object
• A structure
• A C built in type
• An Objective-C built in type
29. Fill the blank.

NSCountedSet : <>  : NSObject
Answers:
• NSArray : NSClass
• NSMutableArray : NSArray
• NSMutableSet : NSSet
• NSSet
• NSSet : NSArray
30. Can NSDistributedNotificationCenter be used to communicate between multiple machines?
Answers:
• Yes
• No
31. Is the following code correct?

NSMutableArray *a = [NSMutableArray new];

// do something with a

[a release];
Answers:
• Yes
• No
32. What threading API should be used in Cocoa?
Answers:
• CFThread
• pthread
• pth
• NSThread
• None of the above
33. Is the following code correct?

NSMutableArray *a = [NSMutableArray array];

// do something with a

[a release];
Answers:
• Yes
• No
34. How can you move a view?
Answers:
• You cannot
• By calling move: method
• By changing the frame with setFrame:
• None of the above
35. Fill the blank.
NSButton : <> : NSObject
Answers:
• NSControl :
• NSWidget : NSView : NSResponder
• NSResponder
• NSWidget
• NSControl : NSView : NSResponder
36. How is a GUI usually created in Cocoa?
Answers:
• With interface builder
• By editing xml files manually
• Programmatically
• None of the above
37. Is it possible to create events and dispatch them to the application?
Answers:
• Yes
• No
38. Can POSIX thread be used in Cocoa?
Answers:
• Yes
• No
39. Is the following code valid?

NSSize s = NSMakeSize(10, 10);

int values[20];

values[s.height] = 5;
Answers:
• Compile error
• Runtime error
• Valid code
40. Is NSString mutable?
Answers:
• Yes
• No
41. Can you use malloc/free in a Cocoa application?
Answers:
• Yes
• Yes, but only in a separate C library
• Yes, but we can use only malloc; free is not needed
• No
42. What is NSViewHeightSizable constant used for?
Answers:
• Transparency
• Scrolling
• Autoresizing
• Magnification
• None of the above
43. Can poll() be used to fetch Cocoa events?
Answers:
• Yes
• No
44. What is a toll-free bridged class?
Answers:
• A superclass of another class
• A class that can be interchanged with another class by casting
• A wrapper around another class
• A class with no memory need
• None of the above
45. What is Cocoa?
Answers:
• A language
• A tree
• A system
• A framework
• None of the above
46. Is NSRunLoop thread safe?
Answers:
• Yes
• No
47. Which of the following platforms supports Cocoa?
Answers:
• Windows
• Linux
• Mac OSX
• Solaris
• None of the above
48. Where should application resources be usually put?
Answers:
• In /System
• In /Library
• Within the application's bundle
• In /Resources
• None of the above
49. Is there a double click event?
Answers:
• Yes
• No
50. What is the normal way of handling Cocoa events?
Answers:
• By polling for events
• By registering an event watcher
• By implementing NSResponder methods in subclasses
• None of the above
51. Which of the following classes manages the computer's global notifications?
Answers:
• NSNotificationCenter
• NSDistributedNotificationCenter
• NSGlobalNotificationCenter
• NSSystemNotificationCenter
52. Can a notified object find out from where the notification is coming? (Sending object)
Answers:
• Yes
• No
53. How wide is unichar on a 32bit machine?
Answers:
• 8bit
• 16bit
• 32bit
• 64bit
• 128bit
54. Is the following code correct?

NSRect a = NSMakeRect(0, 1, 2, 3) + NSMakeRect(0, 1, 2, 3);
Answers:
• Yes
• No
55. Fill the blank.

NSNotification : <> : NSObject
Answers:
• NSEvent
• NSCenter
• NSDistributed
• NSGeneralNotification
• Nothing is required to fill the blank
56. Is the following code valid?

NSRect r;
   
r.size = NSMakeSize(10, 10);
r.origin = NSMakePoint(-5, -5);
Answers:
• Yes
• No
57. Is the following code correct?

NSMutableArray *a = [[NSMutableArray new] autorelease];

// do something with a

[a release];
Answers:
• Yes
• No
58. Can you detach threads in Cocoa?
Answers:
• Yes
• No
59. Which of the following is a valid Uniform Type Identifier?
Answers:
• JPEG
• .jpg
• public.jpeg
• image/jpeg
• .jpeg
60. Is the following code correct?

- (void)myMethod:(NSString **)s {
     *s = [[NSString alloc] init]:
}
Answers:
• Yes
• No