[OC Fourth day] "mastering" 03-self used in Object methods

Source: Internet
Author: User
Tags print object

"Mastering" 03-self used in Object methods

Self refers to the object that invokes the current object's method.
Once again, the code will understand.

"Mastering" 04-self used in class methods

The essence of [P class] Return is the current class (class object)

[Self Run]

"Understanding" 05-self modifier variables

Self->speed = speed;
Local variables temporarily mask the scope   of global variables if they have the same name int Ten ;    A  = A;
    Self-> speed accesses a local variable that is accessed by the instance variable plus self after the instance variable of the    class is    not added to the self.

"Mastering" 08-Inherited code implementation

  Bigyellowdog itself (the actual definition) does not eat and run behavior,  but the Bigyellowdog parent class Dog has  so, Bigyellowdog also have, because inherited
The inheritance format is marvelous

@interface Dog:animal

"Mastering" 11-instance variable modifier introduction

    @public        Public, the @private private can be accessed anywhere through an instance        object       , indicating that only @protected protected type can be used in the current class    , indicating access only in the current class and subclass

"Mastering" The effects of 12-instance variable modifiers on subclasses

Interview question:    @private types of variables, can the quilt class inherit?    subclasses can inherit all the instance variables and methods of the parent class    However, not all of them can access        @private type of variable, can the quilt class access?    Cannot access

"Mastering" The private variables in the 13-OC

Person.m

" Person.h " // defining instance variables in. m ///Pure private variable, which can only be used in the current class, cannot be inherited by the quilt class, and cannot be accessed int m = ; @implementationperson-(void) run{    NSLog (@ " people walking, speed is%d"  , M);} -(void) eat{    NSLog (@ "eat:m =%d", M);} @end

"Mastering" private Methods in 14-oc

. h file, which can be seen as an external interface
Private methods are not declared but implemented    only in their own class class [self private Method] Access
Private method (relative private) cannot inherit from quilt class

It's simple, but you can watch the video again.

Introduction and rewriting of "mastery" 15-description method

When weprint object D in the format of% @, when the object's description method object is called, if the description method of the parent class is not overridden, the
This should be more important, this one, it's pretty detailed.
return [NSString stringWithFormat:@ " Age:%d, color:%d", _age,_color];
   // Print class information        in the form of%@ NSLog (@ "class");

"Mastering" the implementation of 16-polymorphic

Polymorphic nature needs to go deep into memory, but there are limitations, such as you think about how the parent class can use subclasses, because memory has this method
The parent class cannot use the subclass's unique method, because it is the compile check, a check the parent class without this method directly error, only downward transformation

[OC Fourth day] "mastering" 03-self used in Object methods

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.