Categories: Programming

Top 25 Objective C Interview Questions & Answers

1) What Objective-C program consists of?

The objective-c program basically consists of

  • Preprocessor commands
  • Interface
  • Implementation
  • Method
  • Variables
  • Statements & Expressions
  • Comments

2) Explain what is OOP?

OOP means Object Oriented Programming; it is a type of programming technique that helps to manage a set of objects in a system.  With the help of various programming languages, this method helps to develop several computer programs and applications.

3) What is the protocol in Objective C?

In Objective-C, a protocol is a language feature, that provides multiple inheritances in a single inheritance language.  Objective C supports two types of protocol.

  • Ad hoc protocols known as informal protocol
  • Compiler protocols are known as formal protocol

4) What is the difference between polymorphism and abstraction?

Abstraction in OOP is the process of reducing the unwanted data and maintaining only the relevant data for the users while polymorphism enables an object to execute their functions in two or more forms.

5) What is parsing? Mention which class can you use for parsing of XML in iPhone?

Parsing is the process to access the data in the XML element. We can use class “NSXML” parser for parsing XML in iPhone.

6) Which class is used to establish a connection between applications to the web server?

The class used to establish a connection between applications to the web server are

  • NSURL
  • NSURL REQUEST
  • NSURL CONNECTION

7) What is an accessor method?

Accessor methods are methods belonging to a class that enables you to get and set the values of instance valuable contained within the class.

8) What is #import?

#import is a C pre-processor construct to avoid multiple inclusions of the same file.

9) What is the class of a constant string?

It is NSConstantString.

NXConstantString *myString = @ “my string”;

10) List out the methods used in NSURL connection?

Methods used in NSURL connection are

  • Connection did receive response
  • Connection did receive data
  • Connection fails with error
  • Connection did finish loading

11) Explain class definition in Objective-C?

A class definition begins with the keyword @interface followed by the interface (class) name, and the class body, closed by a pair of curly braces.  In Objective-C, all classed are retrieved from the base class called NSObject. It gives basic methods like memory allocation and initialization.

12) What is the use of category in Objective-C?

The use of category in Objective-C is to extend an existing class by appending behavior that is useful only in certain situations. In order to add such extension to existing classes, objective –C provides extensions and categories. The syntax used to define a category is @interface keyword.

13) What are the characteristics of the category?

Characteristics of category include:

  • Even if you don’t have the original source code for implementation, a category can be declared for any class
  • Any methods that you define in a category will be available to all instances of the original class as well as any sub-classes for the original class
  • At runtime, there is no variation between a method appended by a category and one that is implemented by the original class

14) What is single inheritance in Objective-C?

The objective-c subclass can only be obtained from a single direct parent class this concept is known as “single inheritance.”

15) What is polymorphism in Objective-C?

Polymorphism in Objective-C is referred to a capability of the base class pointer to call the function.

16) When would you use NSArray and NSMutableArray?

  • NSArray: You will use an NS array when data in the array don’t change. For example, the company name you will put in NS Array so that no one can manipulate it.
  • NSMutableArray: This array will be used in an array when data in an array will change. For instance, if you are passing an array to function and that function will append some elements in that array then you will choose NSMutable Array.

17) What is synthesized in Objective-C?

Once you have declared the property in Objective-C, you have to tell the compiler instantly by using synthesize directive.  This will tell the compiler to generate a getter&setter message.

18) How is string represented in Objective-C?

In Objective-C, the string is represented by using NSS string and its sub-class NSMutableString provides several ways for creating string objects.

19) Explain what is data encapsulation in Objective-C?

In Objective-C, data encapsulation is referred to as the mechanism of connecting the data and the functions that use them.

20) Explain how to call a function in Objective-C?

To call the function in Objective-C, you have to do Account -> Object Name -> Display account information ->  Method name

21) What are objective- C blocks?

In Objective-C class, there is an object that combines data with related behavior.  It enables you to form distinct segments of code that can be passed around to functions or methods as if they were values.  Objective-C blocks can be added to collections like NSDictionary or NSArray.

22) What is the main difference between function calls and messages?

The main difference between a function call and message is that a function and its arguments are linked together in the compiled code, but a message and a receiving object are not linked until the program is executing and the message is sent.

23) How messaging works in Objective-C?

Messaging is not bound to method implementation until runtime in Objective-C. The compiler transforms a message expression, into a call on a messaging function, objc_msgSend().  This function connects the receiver and the name of the method mentioned in the message.

24) Explain how the class “IMPLEMENTATION” is represented in Objective-C?

In Objective-C the class “ IMPLEMENTATION” is represented with @implementation directive and ends with @end.

25) What is dot notation?

Dot notation involves assessing an instance variable by determining a class “instance” followed by a “dot” followed in turn by the name of the instance variable or property to be accessed.

26) NS object is a parent class or derived class?

NS object is the parent class and consists of a number of instance variables and instance methods.

Share

Leave a Reply

Your email address will not be published. Required fields are marked*

View Comments

  • Hi there.

    I believe that question 9 has got a misspelled word. Did you guys not mean NSConstantString instead of NXConstantString?

    --
    Best,
    Luiz

    Cancel reply

    Leave a Reply

    Your email address will not be published. Required fields are marked*

    • updated! Thanks for pointing this out

      Cancel reply

      Leave a Reply

      Your email address will not be published. Required fields are marked*