O'Reilly logo

Programming in Objective-C, Sixth Edition by Stephen G. Kochan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Classes Owning Their Objects

Can you explain the output from Program 8.5?

Program 8.5

#import "Rectangle.h"#import "XYPoint.h"int main (int argc, char * argv[]){   @autoreleasepool {      Rectangle *myRect = [[Rectangle alloc] init];      XYPoint   *myPoint = [[XYPoint alloc] init];      [myPoint setX: 100 andY: 200];      [myRect setWidth: 5 andHeight: 8];      myRect.origin = myPoint;      NSLog (@"Origin at (%i, %i)", myRect.origin.x, myRect.origin.y);      [myPoint setX: 50 andY: 50];      NSLog (@"Origin at (%i, %i)", myRect.origin.x, myRect.origin.y);   }   return 0;}

Program 8.5 Output

Origin at (100, 200)Origin at (50, 50)

You changed myPoint from (100, 200) in the program to (50, 50), and apparently ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required