m-jansen
asked on
method call problems
I have two classes
class one contains
-Array with content
-Method to print the array
class two contains
-methods to manipulate the array in class 1
-calls the one.print
The problem is:
To print the manipulated array made by the methods in class 2, by calling the print method in class one.
I just get the default content when doing that.
class one contains
-Array with content
-Method to print the array
class two contains
-methods to manipulate the array in class 1
-calls the one.print
The problem is:
To print the manipulated array made by the methods in class 2, by calling the print method in class one.
I just get the default content when doing that.
Are you sure you are manipulating directly the array that class one holds?
ASKER
The array updated with the new content.
ASKER
I think the problem is that I make a new instance when calling the print method
If you create a new array then make sure you are assiging the new array to class one array variable.
I hope the following is clear to you that it is a mistake and will not change the class one array:
in class two:
method XXX
{
array x = class one.array;
x = new array;
}
I hope the following is clear to you that it is a mistake and will not change the class one array:
in class two:
method XXX
{
array x = class one.array;
x = new array;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I guess mightyone ment to write:
classA.str[iidx] = s;
instead of
>> A[idx] = s;
classA.str[iidx] = s;
instead of
>> A[idx] = s;
of course sorry for that ;-)
and change
set(String s, int idx){
A[idx] = s;
}
to
public void set(String s, int idx){
A[idx] = s;
}
set(String s, int idx){
A[idx] = s;
}
to
public void set(String s, int idx){
A[idx] = s;
}
ASKER
Thanx