Use and Inheritance of Classes

Source: Internet
Author: User
// Rectangular class declaration and implementation
# Import <Foundation/Foundation. h> @ interface rect2: nsobject {// float Chang; // float W ;}@ property float Chang; @ property float W;-(float) sizeofrect; @ end # import "rect2.h" @ implementation rect2 // @ synthesize Chang; // @ synthesize W;-(float) sizeofrect {nslog (@ "% @", self ); return (self. chang) * (self. w) ;}@ end // The declaration and definition of the cuboid class # import <Foundation/Foundation. h> # import "rect2.h" @ interface lifangti: rect2 {// float height;} @ property float height;-(float) tijifor; @ end # import "lifangti. H "@ implementation lifangti-(float) tijifor {return self. W * self. height * self. chang ;}@ end # import "viewcontroller. H "# import" lifangti. H "# import" rect2.h "@ interface viewcontroller () @ end @ implementation viewcontroller-(void) viewdidload {[Super viewdidload]; rect2 * rect = [[rect2 alloc] init]; rect. chang = 1; rect. W = 2; nslog (@ "% @", rect); nslog (@ "% F", [rect sizeofrect]); lifangti * lifangti = [[lifangti alloc] init]; lifangti. chang = 1.0; lifangti. W = 3.0; lifangti. height = 3.0; nslog (@ "% F", [lifangti tijifor]);}

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.