Hello all,
i have noticed some odd behaviour from methods:
if u have a class with 2 setMethods for example, and one passes its calculated value on to the other method, the return value i get from the latter will always be the same as when the corresponding instance variable was initialised, to make myself more clear, i did something like this:
so as you can see i tried to pass on a parameter from one method to another one, within the same class
but now comes the odd thing (at least odd to me for i dont understand it :-) :
when constructing an object in your main method that accesses the above class the following will happen:
if i call for example (assuming i have constructed an object variable named "testicus"):
System.out.println(testicus.getY());
this will print the correct value (whatever number was entered)
BUT:
int number = testicus.getY();
will assign a value of 0 to "number"! (the value which was used to initialize the "y" instance variable in the class
Test basically this does NOT happen if i make a direct call from my main method like this for example:
testicus.setY(5);
if i try
int number = testicus.getY();
again, it will assign the correct input value to the var "number".
So my questions are: what happens to values when they are passed on from one method to another one?
Why can't they be assigned correctly to a variable in the main method (instead giving them their initialisation values)?
Is there any way how i still can get my desired outcome (assigning a variable in the main method with the correct result) using methods to pass on parameters to themselves?
i have been looking all over the internet and couldnt find an answer. i would really appreciate your help!
thanks in advance,
chris
[This message has been edited by Cindy Glass (edited October 31, 2001).]