home *** CD-ROM | disk | FTP | other *** search
- /*Objective_C Implementation of the Apple Class: Apple.m*/
-
- #import "Apple.h"
-
- @implementation Apple : Fruit
-
- /* Initialize a new apple object. */
- -init
- {
- [super init]; // Do Fruit's init. Now my own:
- [self setFlavor:"Delicious" diameter:3 color:"red"]; // initialize
- return self; // return the new instance
- }
-
- /* Set the flavor instance variable. */
- -setFlavor:(char*)aFlavor
- {
- flavor=aFlavor;
- return self;
- }
-
- /* Return the value of the flavor instance variable. */
- -(char*)flavor
- {
- return flavor;
- }
-
- /* Set all the instance variables in the Apple objects. */
- -setFlavor:(char*)aFlavor diameter: (int) aSize color:(char*)aColor
- {
- [self setFlavor:aFlavor]; //set flavor
- [self setDiameter:aSize]; //set diameter
- [self setColor:aColor]; //set color
- return self;
- }
-
- /* Tell an apple to increase its diameter. */
- -grow
- {
- [self setDiameter:([self diameter] + 2)]; //grow by 2
- return self;
- }
-
- @end
-