next up previous contents index
Next: Point et ColorPoint in Up: Un exemple dans chaque Previous: Point et ColorPoint in

 

Point et ColorPoint in Objective-C 

#import <appkit/appkit.h>

@interface Point : Object {// instance variables int x; } - (int) getx;
- setx:(int) y; @end

@implementation Point - (int) getx { return x;} - setx:(int) y { x=y; return self;}
@end

@interface ColorPoint : Point {// instance variables char * col; } - (char ) getcol;
- setcol:(char
) c;
@end

@implementation ColorPoint : Point - (char ) getcol { return col;} - setcol:(char ) c { free(col); col=(char *)malloc(strlen(c));strcpy(col,c); return self;} @end

main() { id p, cp;

p=[[Point new] setx: 3]; cp=[[[ColorPoint new] setx: 4] setcol: "blue"];

printf("Point at %d, %s ColorPoint at %d\n", [p getx], [cp getcol], [cp getx]); exit(0); }



Roberto DiCosmo
Mon Jun 3 18:29:31 MET DST 1996