Writting class question

public Complex add( Complex right ) {return new Complex( real + right.real,imaginary + right.imaginary );What is the function of right.imaginary?
[173 byte] By [PaTa] at [2007-11-26 21:53:19]
# 1
complex numbers have a real part and the imaginary part, so to two complex numbers together you must add the complexes and the imaginaries.. eh?
mkoryaka at 2007-7-10 3:47:32 > top of Java-index,Java Essentials,Java Programming...
# 2
but why dun just set it to:this.real=real;orreal.right?
PaTa at 2007-7-10 3:47:32 > top of Java-index,Java Essentials,Java Programming...
# 3

Excuse me, is this a joke or what? You're asking questions out of context, and we're trying to guess the intention of the piece of code you've provided (without code tags; please remember those).

The natural guess is that this a method to add one complex number to another complex number. To add two complex numbers, you need to add the real parts and add the imaginary parts. Which is what the code does.

OleVVa at 2007-7-10 3:47:32 > top of Java-index,Java Essentials,Java Programming...
# 4

that question doesnt make sense.

ill try to answer anyway:

if you set this.real to something from the param named "right", then what would you return?

i think the point here is to add stuff from this, to the param, AND make a new complex object without modifying either this or the param

because if you do

a = 1

b = 3

and then

c = a + b

then c should be 4 but a and b should still have their old values.

mkoryaka at 2007-7-10 3:47:32 > top of Java-index,Java Essentials,Java Programming...