December 2012
Beginner
552 pages
12h 58m
English
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 it also changed the rectangle’s ...
Read now
Unlock full access