Objective-C Upwork Test

0
141

We don’t guarantee that all provided answers are correct.

Objective-C allows you to define protocol, which declare the method expected to be used for a particular situation. Protocol are implemented in the classes conforming to the protocol. The methods under keyword (…) must be implemented in the classes that conform the protocol and the method under (…) keyword are special optional
to implement.

Answer

  • @required, @optonal
  • @optonal, @required
  • @strong, @optonal
  • @required, @weak

What is the best way to convert NSNumber into NSString?
Answer

  • int num = {number intValue};
    NSString *string = [NSString stringWithFormat:@” %d”, num};
  • NSString *string = [NSNumber stringValue];
  • NSString *string = [NSString stringWithFormat:@” %f”, (float) number};

How do you free an object?
Answer

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

Objective-c provide a range of methods to work with NSNumber. Which of the following methods create and returns an NSNumber object containing a given value, treating it as an NSInteger.
Answer

  • `+ (NSNumber *) numberWithInt: (int) value`
  • `- (NSInteger)integerValue`
  • `+ (NSNumber *)numberWithInt: (NSInteger)value`
  • `+ (NSNumber *)numberWithInt:(NSInteger)value `

In Objective-C, retain counts are the way in which memory is managed. When you create an object, it has a retaincount of (…). When you send an object a retain message, its retain count in incremented by (…). When you send an object release
message it’s retained count is decremented by (…). When you send an object a auto-release message, it’s retain count is decremented by (…) at some stage in the future. If an object count is reduced to (…), it is deallocated.

Answer

  • 1, 1, 1, 1, 0
  • 0, 1, 1, 1, 0
  • 1, 1, 1, 1, 1
  • 0, 1, 1, 1, 1

Can you call C++ code from the Objective-C environment?
Answer

  • Yes, from any .nm file
  • Yes, from any .cpp file
  • No

In Objective-C, Exceptions can be handled using the standard common pattern found in most other high-level programing languages. First, you need to place any code that might result in an exception in an (…) block. Then, if an exception is a thrown, the corresponding (…) block is executed to handle the problem. The (…) block is called afterwards, regardless of whether or not an exception occurred.
Answer

  • `@ catch(), @try, @finally`
  • `@try @throw, @catch()`
  • `@finally, @catch(), @throw `
  • `@try, @catch, @finally`

Look at below code and provide the reference counter value after it executes:
Object *anObj = [[Object alloc] int];
[anObj retain];
[anObj release];
[anObj release];
Answer

  • Reference counter will be 1
  • Reference counter will be 0, anObj will be deallocated automatically
  • Reference counter will be 0, anObj will be ready for the deallocation

Which of the following is NOT characteristic a category?
Answer

  • A category is adding private method and private variables that are not specific to the class and the original implementation
  • A category can be declared for any class, even if you don’t have the original implementation source code
  • Any methods that you declare in a category will be available to all instance of the original class, as well as any subclass of the original class
  • At run-time, there no difference between a method added by a category and one that is implemented by the orignal class

Which of the following contains the INCORRECT definition of a preprocessor directive
Answer

  • `#define`: Substitues a preprocessor macro
  • `#include`: Inserts a particular header from another file
  • `#under`: Undefines a preprocessor macro
  • `#error`: Issues special commands to the compiler using a standardized method
  • `#ifdef`: Returns true if this macro is defined

The Objective-C code …
@interface MyClass : NSObject

@end
Answer

  • Indicates MyClass is part of the Sample category
  • Indicates MyClass conforms to the Sample category
  • Indicates MyClass conforms to the Sample Protocol
  • Is not valid Objective-C syntax

Which of the following is a Singleton.
Answer

  • [NSFileManager defaultManager]
  • [NSFileManager objects]
  • [NSFileManager defaultManager}
  • (NSFileManager defaultManager* objects)

When a object’s retainCount reaches 0, which message is automatically sent to that object?
Answer

  • dealloc
  • alloc
  • automated
  • object

If a is in Integer, the expression !a?
Answer

  • Uses the logical negation operator
  • Has the value 0 if a is non-zero
  • Has the value 1, if a is zero
  • All of the above

In (…), the system uses the same reference counting system as (…), but it inserts the appropriate memory management method calls for us at compile-time.
Answer

  • MRR, ARC
  • ARC, MRR
  • ARC, Garbage Collection
  • MRR, Garbage Collection
  • None of the above

LEAVE A REPLY

Please enter your comment!
Please enter your name here