OC object-oriented preliminary

Source: Internet
Author: User
// 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

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.