Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8656045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:10:57+00:00 2026-06-12T15:10:57+00:00

Kochan- Programming in objective-C. Can’t understand two lines of code. (marked as comments) XYPoint.h

  • 0

Kochan- Programming in objective-C.

Can’t understand two lines of code. (marked as “comments”)

XYPoint.h Interface File

#import <Foundation/Foundation.h>
@interface XYPoint: NSObject
{
int x;
int y;
}
@property int x, y;
-(void) setX: (int) xVal andY: (int) yVal;    
@end

XYPoint.m Implementation File

#import "XYPoint.h"
@implementation XYPoint.h
@synthesize x, y;
-(void) setX: (int) xVal andY: (int) yVal
{
x = xVal;
y = yVal;
}
@end

Rectangle.h Interface File

#import <Foundation/Foundation.h>
@class XYPoint;
@interface Rectangle: NSObject
{
int width;
int height;
XYPoint *origin; // What does this line mean?  
}
@property int width, height;
-(XYPoint *) origin;
-(void) setOrigin: (XYPoint *) pt;
-(void) setWidth: (int) w andHeight: (int) h;
-(int) area;
-(int) perimeter;
@end 

Rectangle.m Implementation File

#import "Rectangle.h"
@implementation Rectangle
@synthesize width, height;
-(void) setWidth: (int) w andHeight: (int) h
{
width = w;
height = h;
}
–(void) setOrigin: (XYPoint *) pt
{
origin = pt;
}
–(int) area
{
return width * height;
}
–(int) perimeter
{
return (width + height) * 2;
}
–(XYPoint *) origin
{
return origin;
}
@end

Test Program

#import "Rectangle.h"
#import "XYPoint.h"
int main (int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Rectangle *myRect = [[Rectangle alloc] init];
XYPoint *myPoint = [[XYPoint alloc] init];
[myPoint setX: 100 andY: 200];
[myRect setWidth: 5 andHeight: 8];
myRect.origin = myPoint; // What does this line mean? 
NSLog (@"Rectangle w = %i, h = %i", myRect.width, myRect.height);
NSLog (@"Origin at (%i, %i)",myRect.origin.x, myRect.origin.y);
NSLog (@"Area = %i, Perimeter = %i",
[myRect area], [myRect perimeter]);
[myRect release];
[myPoint release];
[pool drain];
return 0;
}

Output

Rectangle w = 5, h = 8
Origin at (100, 200)
Area = 40, Perimeter = 26

Kochan’s explanation of this line
myRect.origin = myPoint;
is: “After setting the width and the height of the rectangle to 5 and 8, respectively, you
invoked the setOrigin method to set the rectangle’s origin to the point indicated by
myPoint.”
But we didn’t invoked setOrigin!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:10:59+00:00Added an answer on June 12, 2026 at 3:10 pm
    myRect.origin = myPoint;
    

    is the same (almost) as

    [myRect setOrigin:myPoint];
    

    It’s just a different way of achieving the same result.

    As Mahesh explained,

    XPoint *origin;
    

    Declares a pointer (variable) called origin, of type XPoint.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been coding my way through Steve Kochan's Programming in Objective-C 2.0 book. I'm
Being relatively new to programming--think Programming in Objective-C by Kochan, Chapter 15--I'm wondering if
I am reading Programming in Objective-C 4th Ed. by Stephen G. Kochan. In the
Hi, guys! Currently I'm reading a book Programming in Objective-C by Stephen Kochan. Actually
I am learning Objective-C using Stephen Kochan's excellent book Programming in Objective-C 2.0. I
I'm following the book of Programming in Objective-C by Stephen G. Kochan. I was
I have been reading about bit operators in Objective-C in Kochan's book, Programming in
I'm learning objective-c from Programming in objective-c author Kochan. 3rd edition. In Chapter 8
I came across this code in Stephen G Kochan's book, Programming in c. Is
I'm reading a book called programming in objective-c by Stephen Kochan. I've been reading

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.