[Person new] has done three things:
1) Request Memory space
2) Initialize the instance
3) Return to the first address of the space
Instance variables are saved in the heap area
"Pointer (object name) saved in the stack area
Object methods are saved in the code area
The call method first finds the pointer to the heap area that P points to-isa and then finds the method of the code area that Isa points to
Object methods can only be called by objects, class methods can only be called by classes, and cannot be called as functions
The function belongs to the entire file, and the function declaration can be inside main or outside the main function, except @interface @end
Function:
1) So the functions are all parallel.
2) function has no affiliation
3) can be used when using the direct drop
4) You cannot access member variables in an object
@interface @end can not be nested
Member variables cannot be initialized at declaration time
Member variables and methods cannot be modified with static
[Person new] has done three things:
1) Request Memory space
2) Initialize the instance variable
3) Return to the first address of the space
Which area of the memory is requested for space:
New time to apply for space in the heap area of space
If the instance variable is a base type, it is initialized to 0 at this time.
If it is a string type, it is initialized to null
Where is the instance variable saved?
Heap Area
P (pointer variable name) stack area
Object methods are saved in the code area
Why [P run]; Can we call the method? How to invoke the
First find the space of P, then find the _isa, and then find the code space pointed to by _isa, and then find the method in the space
15) class Method:
Class method call does not require an instance
Invocation of class method [Class name class method name]
class method name and object method name can be the same
The benefit of class methods is that you do not need to create objects, access them directly through the class name, and do not need to create any space in the heap area
The class method does not allow access to the instance variable, you can pass a parameter
Instance methods can access instance variables
Object methods can call other methods of an object
Other methods of the class can be called in a class method, can be used with self, or a method method can be called with another class name
An object method can also be called in a class method, except by passing an object through a parameter or creating an object.
Class method cannot call itself (dead loop)
[[Car alloc] init] equals [car new]
Anonymous classes are used as method parameters:
Person *p = [[Person alloc] init]
[P Gohome:[car New];
16) Package:
Instance variables can only be accessed by object methods of the current class
Writing specification for Set methods:
1) The Set method must be an object method
2) The Set method must not have a return value
3) The Set method must start with set
4) set followed by the instance variable minus the underscore, and the first letter capitalized
5) The Set method must have parameters, and the type of the parameter and the instance variable are the same
6) There is no method overload in OC, the method in OC cannot have the same name
7) The variable defined by static can only be used in the current file
() Self:
Self refers to the object that invokes the current method
Self refers to the current class method
Person *p = [person new];
[P class]; Returns the current class
A variable with the same name as a global variable can be defined inside a function
Local variables temporarily mask the scope of global variables if they have the same name (can be distinguished by self)
18) Inheritance:
The private property of the base class is inherited, but cannot be used
In OC is single inheritance
Call the object method to find out if there is a method in this class, otherwise find the parent class
Supports multiple layers of inheritance
The variable default modifier is @protect
@private can only be used in object methods of the current class
Variables defined in. m are private variables
Methods that are not declared in. h are private methods
Private methods cannot inherit from a quilt class
NSLog ("%p", D); Print Object Address
NSLog ("%@", D); Print class name + object address
Prints Object D in%@ format, at which point the description method of the object is called, and if the description method is not overridden in the subclass, the parent class's
[D class]; Get the Dog class
Class methods cannot access instance variables
Do not use%@ and self in the description method will cause a dead loop
OC Encapsulation Inheritance and instantiation