// Animal. h file # import <Foundation/Foundation. h> @ interface animal: nsobject {@ private int _ feets; int _ eyes; nsstring * _ corlor;}-(void) cry;-(instancetype) initwithnumber :( INT) feets; -(void) crywithdb: (INT) size; + (nsstring *) letitgo;-(void) seteyes :( INT) eyes;-(INT) geteyes; @ end // animal. M file @ implementation animal-(void) cry {nslog (@ "% @: % s", @ "crying" ,__ function _);}-(instancetype) initwithnumber :( INT) feets {If ([Super init]) {_ feets = feets; [email protected] "ghost";} return self ;}- (void) crywithdb: (INT) size {nslog (@ "crying with % d DB", size) ;}+ (nsstring *) letitgo {return @ "It is so beatiful! ";}- (Void) seteyes :( INT) Eyes {_ eyes = eyes;}-(INT) geteyes {return _ eyes ;}@ end // cat. h file # import "animal. H "@ interface Cat: Animal-(void) cry1;-(void) cry3; @ end // cat. M file # import "cat. H "@ implementation cat-(void) cry1 {nslog (@" % @: % s ", @" Crying _ ",__ function _);}-(void) cry {nslog (@ "% @: % s", @ "Crying _" ,__ function _);}-(void) cry3 {nslog (@ "% @: % s ", @" Crying ______ ",__ function _) ;}@ end // Tig. h file # import "cat. H "@ interface Tiger: CAT-(void) cry2; @ end // Tig. M file # import "Tiger. H "@ implementation tiger-(void) cry2 {nslog (@" % @: % s ", @" Crying ___ ",__ function _);}-(void) cry1 {nslog (@ "% @: % s", @ "Crying ____" ,__ function _);}-(void) cry {nslog (@ "% @: % s ", @" Crying _____ ",__ function _);} @ end // viewcontroller. hfile # import <uikit/uikit. h> @ interface viewcontroller: uiviewcontroller @ end // viewcontroller. M file # import "viewcontroller. H "# import" animal. H "# import" cat. H "# import" Tiger. H "@ interface viewcontroller () @ end @ implementation viewcontroller-(void) viewdidload {[Super viewdidload]; animal * animal = [[animal alloc] initwithnumber: 4]; [Animal crywithdb: 50]; nsstring * BBS = [animal letitgo]; nslog (@ "% @", BBS); [animal seteyes: 2]; nslog (@ "% d", animal. geteyes); CAT * cat = [[Cat alloc] init]; tiger * tiger = [[Tiger alloc] init]; [animal cry]; [cat cry]; [tiger cry]; [Cat cry1]; [Tiger cry1]; [Tiger cry2]; [animal release]; [Cat release]; [Tiger release]; animal = [[Cat alloc] init]; [animal cry]; [animal release]; animal = [[Tiger alloc] init]; [animal cry]; cat = [[Tiger alloc] init]; [cat cry]; [animal release]; [Cat release]; animal = [[Cat alloc] init]; [Animal cry3];}-(void) didreceivememorywarning {[Super didreceivemorywarning]; // dispose of any resources that can be recreated .} @ end
OC object-oriented preliminary