Objective-C Test Answers
·
1. What comments are supported in
Obj-C?
Answers:
• // Line comments
• /* Block comments */
• # Line comments
• ; Line comments
• -[[ block
comments ]]
2. What is the default visibility for instance
variables?
Answers:
• @private
• @package
• @public
• @protected
• None of the
above
3. What is the id type?
Answers:
• 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
4. What is not supported in Obj-C?
Answers:
• Recursive
method call
• Variable
argument count to method
• Byte
manipulation
• Method argument default
value
• None of the
above
5. What is the isa variable in objects?
Answers:
• Object size
• Object memory
footprint
• Object class
identification
• Object serial
numbe
• None of the
above
6. What type of variable do you need to use to
implement singletons?
Answers:
• static
• auto
• const
• volatile
7. Which of the following declares a protocol?
Answers:
• @proto
ProtocolName
• protocol
ProtocolName {};
• @protocol ProtocolName
• @interface
<ProtocolName>
• @interface
ProtocolName::Protocol
8. When using the garbage collector, which
method, that is normally called without the collector, is not called on your
objects where they are collected?
Answers:
• free
• dealloc
• destroy
• uninit
9. Which of the following creates a class that
conforms to a protocol?
Answers:
• @interface
ClassName [ProtocolName]
• @interface ClassName
<ProtocolName>
• @interface
ClassName < ProtocolName
• @interface
ClassName::ProtocolName
• @interface
ClassName(ProtocolName)
10. What is true regarding @protected?
Answers:
• 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
11. What is nil?
Answers:
• The null object
• The null class
• It doesn't
exist
• None of the
above
12. What is true regarding @public?
Answers:
• It doesn't
exist in Objective-C
• It breaks
encapsulation
• It can be used
only on singleton objects
• None of the above
13. What is a protocol?
Answers:
• A class that
uses functions instead of methods
• A method
signature
• A class
signature
• An interface without an
implementation
• None of the
above
14. In which version of Objective-C did the
fast enumeration system appear?
Answers:
• 2.0
• 1.5
• 1.0
• 3.0
15. What is an IMP?
Answers:
• 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 pointe
• None of the
above
16. What is a category?
Answers:
• 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
17. How do you allocate an object?
Answers:
• MyClass *obj =
malloc(sizeof(MyClass));
• MyClass *obj = [MyClass
alloc];
• MyClass *obj =
alloc(MyClass);
• MyClass *obj = [MyClass
new];
• None of the
above
18. Is the following code a correct
allocation?
MyClass myObj;
[&myObj aMessage];
Answers:
• Yes
• No
19. What is an autoreleased object?
Answers:
• 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
20. In which version of Objective-C did the
properties system appear?
Answers:
• 3.0
• 2.5
• 2.0
• 1.5
• 1.0
21. What is a @finally block?
Answers:
• 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
22. A class can conform to only one protocol.
Answers:
• True
• False
23. What class specifiers are supported?
Answers:
• FINAL
• STATIC
• FAST
• ITERATIVE
• There is no such thing as
class specifiers
24. How do you throw an exception?
Answers:
• Raise Exception
• @throw exception
• RAISE exception
• THROW exception
• None of the
above
25. What does the following imply?
Worker *ceo = [[Worker alloc] init];
ceo->boss = nil;
Answers:
• 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
26. Can an exception caught in @catch be
re-thrown?
Answers:
• Yes
• No
27. Which of the following is false?
Answers:
• Method lookup
is done at runtime
• When a method is called,
the send is automatically available as the sender variable, like self or supe
• Messages can be
sent to nil
• Methods in
static libraries must be present at link time
28. What can you use to avoid the msgSend
function overhead?
Answers:
• SEL
• IMP
• You can't use
anything
• None of the
above
29. What does Obj-C not support?
Answers:
• Instance
variables
• Class variables
• Static
variables
• Automatic
variables
30. 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;
}
int
main (int argc, const char *argv[])
{
printf ("%d %d %d", a (), b (), c
());
return 0;
}
Answers:
• 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