Method overrides (Overrides)

Source: Internet
Author: User

Method overloading: The same method name differs from the number of arguments or types that constitute method overloads. OC has no method overloads

////Animal.h#import<Foundation/Foundation.h>@interfaceAnimal:nsobject-(void) run;-(void) play;@end#import "Animal.h"@implementationAnimal-(void) run{NSLog (@"Run ...");}-(void) play{NSLog (@"play ...");}@end
////Cat.h#import<Foundation/Foundation.h>#import "Animal.h"@interfaceCat:animal@end#import "Cat.h"@implementationCat-(void) run{NSLog (@"Cat Run ...");}-(void) play{NSLog (@"Cat Play ..."); }@end
////Dog.h#import<Foundation/Foundation.h>#import "Animal.h"@interfaceDog:animal@end////DOG.M#import "Dog.h"@implementationDog-(void) run{
[Super Run]; //You can call the Run method of the parent class here NSLog (@"Dog Run ..."); //Override Parent class method }-(void) play{NSLog (@"???? Play ..."); }@end
////main.m#import<Foundation/Foundation.h>#import "Cat.h"#import "Dog.h"intMainintargcConst Char*argv[]) {@autoreleasepool {Cat*cat =[[Cat alloc]init]; [Cat run];//The first way to find out from Cat class is to find the method of rewriting the parent class from the cat's superclass can be written in the Cat method[cat play]; Dog*dog =[[Dog alloc]init];        [Dog run];    [Dog play]; }    return 0;}

Method overrides (Overrides)

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.