If any one can help me please to answer this questions please:

  1. What is the difference between this.dollars and otherMoney.getDollars()
    2.- What the return statement of this method is returning.
    3.- How this method would be called from the main and give an example
    Thank you in advanced.

    // instance methods

    public Money addMoney( Money otherMoney ) {

    int newd = dollars + otherMoney.getDollars();
    int newc = cents + otherMoney.getCents();

    return new Money( newd, newc );

    }

    public Money subtractMoney( Money otherMoney ) {

    int newd = dollars - otherMoney.getDollars();
    int newc = cents - otherMoney.getCents();

    return new Money( newd, newc );
    }

Why I have a feeling that this is your homework ;)
anw heres a semi-answer ...
1 . the diff btw this.dollars and otherMoney.getDollars():
this.variable means refers to the variable in the current class where this.variable appears.
getDollars() is a function for the composite otherMoney which is also of type Money

2 . int newd = dollars + otherMoney.getDollars();
this means that getDollars() returns an Int

3 . this method can be called from the main by creating a new object of type Money

Thanks a lot. I'm new to java this is not really a home work. I did not understand the code, I always get confused by instance method, variables object of the class. That's all my confusion the more I read there always somthing to understand.
for instance this 3 variables:
1- Circle myCircle1;
this is an instance variable of an object correct
2- Circle myCircle2 = new Circle();
this declare a variable and and make a circle an object correct
3- Circle myCircle3 = myCircle2;
this assign myCircle3 to myCircle2
Please clarify if I'm wrong..!!
Thank you for your input

1- Circle myCircle1;
this is an instance variable of an object correct

It is a reference variable.I think so you are a bit confused about reference and instance variable.Read this

this assign myCircle3 to myCircle2

actually it is reverse.Assigning myCircle2 to myCircle3

Edited 3 Years Ago by IIM

This question has already been answered. Start a new discussion instead.