IOS interview questions: OC Basic concept Questions

Source: Internet
Author: User

1. What are classes and objects?


A class is an abstraction of a set of things that have the same characteristics and functions


Object describes the characteristics and behavior of an object.


Class is an abstract object of an object that is an instance of a class


Defines a class in 2.OC, creates objects, and uses objects.


The definition class in OC is divided into the interface part, realizes the partial

Interface part: Characteristics and behavior of the foreign Declaration class

Implementation part: Implementation method, that is, class behavior implementation


Creating an object requires allocating memory space and initial


3. Declare the method, as required. Distinction: Method declaration, method implementation, method execution


4. Inheritance. All features of inheritance


Subclasses can inherit all the declared methods of the parent class and other than the private instance variable

The parent class cannot use the methods and instance variables created by the child class


5.self and Super


Self sends a message to an object to execute a method of that class

Super sends a message to an object executes the method of the parent class


6. Initialize the method. will be customized according to requirements, can write a complete implementation


Example:-(ID) Initwithname: (NSString *) name

Sex: (NSString *) Sex

Age: (int.) Age

{

self = [super init];

if (self)

{

Self.name = name;

Self.sex = sex;

_age = Age

}

return self;

}


7. The visibility of instance variables, and their respective characteristics, what is the default visibility?

How to manipulate the default visibility of an instance variable outside of a class.


@public Public

@protected protected (default)

@private Private


Outside of the class, an instance variable that operates on the default visibility can define the properties of an instance variable, and can declare and implement setter and Getter methods


8. What is the Setter,getter method and how to declare it?


Set-(void) SetName: (NSString *) name

Accessor-(NSString *) name;


9. The role of attributes. How to declare a property, how to implement a property (Declaration and implementation of the corresponding keyword)


Role: Provides external access to automatically generate setter and Getter methods

@propert (Property property) returns the name of a value or parameter Type property

Name of @synthesize property = instance Variable


10. What are the three attributes of a property? There are no features, the use of the scene, the characteristics of the role


Read-Write settings: readonly (read-only) ReadWrite (default)

Semantic settings: Assign (by default both the base data type can be decorated and the object can be decorated)

Retain (Modifier object)

Copy (the object to be decorated and the object being decorated to comply with the <NSCoping> protocol)

Atomicity: Noatomic (no guarantee of multithreading security)

Atomic (Guaranteed multithreading security by default)


11. Internal implementation of the setter and getter methods of attributes


Modified with retain

(void) SetName: (NSString *) name

{

if (_name = name)

{

[_name release];

_name = [name retain];

}

}

(NSString *) name

{

return [[_name retain] autorelease];

}


12. Extension of the class. (Class extension protocol (pair of methods)). Proxy (The object that implements the method in the Protocol)


Category: Add a method to a class without source code no instance variable

Class Purpose declaration: The name of the @interface class (class purpose name)

@end

Class Purpose implementation: The name of the @implementation class

@end

Note: The class intent method is the same as the class method, and the method has high precedence


Extension (extention):(anonymous Class) manage "Private" methods written in. m files can have instance variables

Extended declaration: The name of the @interface class ()

@end

Note: The method declared in the extension must be implemented


Protocol (Protocol): There is no way to implement only method declarations only. h files

The default keyword @require must be implemented @optionol can not be implemented

Statement of agreement: name of the @protocol agreement <NSobject>

Note: A class can accept multiple protocols, separated by "," in < >. multiple inheritance with protocol


13.foundation (frame). Nsstring,nsarray,nsdictionary,nsset (The content of the object is different from each other). (Distinguishing between mutable and immutable, creation of objects, common methods, class characteristics)






14. Memory Management


Understanding of memory Management:

Object ownership: By retain alloc copy is the reference count of the object plus 1

Memory leak: Only allocated a piece of memory, not released

Over-release: Release multiple times

Wild pointer: Pointer to non-existent object

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.