Objective-c Test Answers 2019

Share Objective-c Test Answers

Posted on June 7, 2019

59 Test Questions:

1. What is a category?

• A namespace
• A category is a way to add instance variables to a class which already exists
• A category is a group of classes
• A category is a way to add methods to a class which already exists
• None of the above

2. Is the following code a correct allocation?

MyClass myObj;
[&myObj aMessage];

• Yes
• No

3. What is the default visibility for instance variables?

• @private
• @package
• @public
• @protected
• None of the above

4. Which of the following creates a class that conforms to a protocol?

• @interface ClassName [ProtocolName]
• @interface ClassName <ProtocolName>
• @interface ClassName < ProtocolName
• @interface ClassName::ProtocolName
• @interface ClassName(ProtocolName)

5. What is nil?

• The null object
• The null class
• It doesn’t exist
• None of the above

6. What is not supported in Obj-C?

• Recursive method call
• Variable argument count to method
• Byte manipulation
• Method argument default value
• None of the above

7. What class specifiers are supported?

• There is no such thing as class specifiers

8. Which of the following is false?

• Method lookup is done at runtime
• When a method is called, the send is automatically available as the sender variable, like self or super
• Messages can be sent to nil
• Methods in static libraries must be present at link time

9. What is the Obj-C runtime?

• A C library
• A compiler
• A language
• A dynamic loader

10. What can be linked to an Obj-C program without any particular process?

• C libraries
• Java jar files
• C++ libraries
• scripts
• Executables

11. Which of the following declares a protocol?

• @proto ProtocolName
• protocol ProtocolName {};
• @protocol ProtocolName
• @interface <ProtocolName>
• @interface ProtocolName::Protocol

12. What is an IMP?

• A special type used for computation
• An alias for SEL
• A preprocessor directive defined to the implementation name
• The C type of a method implementation pointer
• None of the above

13. How do you allocate an object?

• MyClass *obj = malloc(sizeof(MyClass));
• MyClass *obj = [MyClass alloc];
• MyClass *obj = alloc(MyClass);
• MyClass *obj = [MyClass new];
• None of the above

14. What is a protocol?

• A class that uses functions instead of methods
• A method signature
• A class signature
• An interface without an implementation
• None of the above

15. What will be the output of the following code?

static int
a (void)
printf («a\n»);
return 0;

static int
b (void)
printf («b\n»);
return 1;

static int
c (void)
printf («c\n»);
return 2;

main (int argc, const char *argv[])
printf («%d %d %d», a (), b (), c ());
return 0;

• a b c 0 1 2
• a b c 2 1 0
• c b a 0 1 2
• c b a 2 1 0
• None of the above

16. What does Obj-C not support?

• Instance variables
• Class variables
• Static variables
• Automatic variables

17. What does the following imply?

Worker *ceo = [[Worker alloc] init];
ceo->boss = nil;

• That the ceo object is statically typed
• That the boss instance variable is declared @protected
• That the boss instance variable is declared @public
• That the ceo is in fact a structure
• This code is not correct

18. What can you do with categories?

• Add instance variables to a class without subclassing it
• Add methods to a class without subclassing it
• Override methods of a class without subclassing it
• None of the above

19. What comments are supported in Obj-C?

• // Line comments
• /* Block comments */
• # Line comments
• ; Line comments
• -[[ block comments ]]

20. What is true regarding C functions inside .m files?

• They can contain Obj-C code
• They are slower than if in a .c files
• They cannot use C libraries 
• They can be static

21. What are @try and @catch?

• Exception handlers
• Exceptions
• Exception keywords
• All of the above

22. What happens if you release an unretained object twice?

• Nothing, too many releases are handled correctly
• Undefined behaviour
• MemoryException is raised
• None of the above

23. What is true regarding strings?

• C string literals are automatically mapped to objects
• C string literals can be used in Obj-C
• Obj-C strings are not of static storage
• Obj-C strings are like C strings

24. What can be used as Object instance variables?

• int
• structures
• pointers
• unions
• None of the above

25. What can you use to avoid the msgSend function overhead?

• You can’t use anything
• None of the above

26. What is the isa variable in objects?

• Object size
• Object memory footprint
• Object class identification
• Object serial number
• None of the above

27. How do you throw an exception?

• raise Exception
• @throw exception
• RAISE exception
• THROW exception
• None of the above

28. If you need to allocate custom memory, in which method will you do so?

• + alloc
• — alloc
• + init
• — init
• None of the above

29. Which of the following is the fastest?

• @synchronized
• Explicit locking
• Condition locking
• Mutex implicit locking

30. What happens if two categories define methods with the same names for the same class?

• The code won’t compile
• At runtime, either method will be called
• A runtime exception will be thrown
• None of the above

31. Which of the following does not happen when you throw an exception in a @synchronized block?

• The object is deallocated
• The object is unlocked
• An exception is thrown
• None of the above

32. What is true regarding messaging?

• Messaging is static and messages are replaced by function call at compile time
• Messaging is fully dynamic, which means you can compile some code that sends a message to a class that doesn’t implement it, and add a category later, in a dynamic library for example
• Messaging is only a syntax sugar to call functions
• None of the above is true

33. What is true regarding @public?

• It doesn’t exist in Objective-C — это не подходит
• It breaks encapsulation
• It can be used only on singleton objects
• None of the above

34. What is a SEL?

• A selection
• The C type of a message selector
• The C type of a class
• A pointer to a method
• None of the above

35. Which of the following is incorrect?

• [self release]
• [super release]
• [AClass release]
• They are all correct

36. What’s the difference between copy and deepCopy?

• They are the same
• deepCopy doesn’t exist
• copy creates a copy at the first level, while deepCopy copies the instance variables
• copy creates a proxy object, while deepCopy allocate a new object
• None of the above

37. Which of the following can be inherited?

• Categories
• Protocols
• Classes
• None of the above

38. A method can be tagged to be called only by a specific class and its subclasses.

• True
• False

39. Which of the following is not recommended?

• Adding an (id)sender argument to methods
• Using static variables inside methods
• Using C code inside Obj-C methods
• None of the above

40. A class can have two methods with the same name, but with different argument types.

• True
• False

41. A class can conform to only one protocol.

• True
• False

42. How do you free an object?

• free(obj)
• [obj dealloc]
• [obj release]
• [obj free]
• None of the above

43. What is the id type?

• A generic C type that Objective-C uses for an arbitrary object
• A memory address type
• A type to hold serialized objects
• The type used for Classes
• None of the above

44. What is a @finally block?

• A block that is executed when the program quits
• A block that is executed within a dynamic library when it’s unloaded
• A block of code that is run whenever an exception is thrown or not
• None of the above

45. Can you send messages to nil?

• Yes
• No

46. In which version of Objective-C did the fast enumeration system appear?

• 2.0
• 1.5
• 1.0
• 3.0

47. What is the C type used to work with objects in Obj-C?

• int
• structure
• pointer
• Array

48. Protocols are like classes; they can inherit.

• True
• False

49. What type of variable do you need to use to implement singletons?

• static
• auto
• const
• Volatile

50. As categories can’t have instance variables, what class could you use to implement a full class only with categories?

• NSArray
• NSMutableDictionary
• NSSet
• None of the above

51. In which version of Objective-C did the properties system appear?

• 3.0
• 2.5
• 2.0
• 1.5
• 1.0

52. How do you include the root “Object” class?

• #include <Object.h>
• #include <objc/Object.h>
• #include <Object/Object.h>
• #include <ROOT.h>
• It depends on the compiler

53. What is true regarding @protected?

• The instance variable is accessible within the class that declares it and within classes that inherit it
• The instance variable is accessible everywhere
• The instance variable is accessible only within the class that declares it.
• This is analogous to private_extern for variables and functions. Any code outside the class implementation’s image that tries to use the instance variable will get a link error
• None of the above

54. In Obj-C 2.0, what do the fast enumeration protocols rely on to provide fast Enumerations?

• C arrays
• Java Vectors
• Ruby hash
• Obj-C Array
• None of the above

55. Which C feature is not supported in Obj-C?

• Bitfields
• Compound literals
• Structures
• C arrays
• Support is compiler dependant

56. When using the garbage collector, which method, that is normally called without the collector, is not called on your objects where they are collected?

• free
• dealloc
• destroy
• Uninit

57. Can an exception caught in @catch be re-thrown?

• Yes
• No

58. What is an autoreleased object?

• A C object.
• A static object.
• An object that is garbage collected.
• An object that will be released when the current AutoreleasePool is deallocated.
• None of the above

59. What is #import

• A namespace import rule
• A namespace definition
• A recursive include
• C preprocessor construct to avoid multiple inclusions of the same file
• None of the above