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)