?
Solved

method call problems

Posted on 2005-03-22
9
Medium Priority
?
224 Views
Last Modified: 2010-03-31
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.
0
Comment
Question by:m-jansen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
9 Comments
 
LVL 15

Expert Comment

by:aozarov
ID: 13604300
Are you sure you are manipulating directly the array that class one holds?
0
 

Author Comment

by:m-jansen
ID: 13604685
The array updated with the new content.
0
 

Author Comment

by:m-jansen
ID: 13604739
I think the problem is that I make a new instance when calling the print method
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:aozarov
ID: 13604743
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;
}
0
 
LVL 6

Accepted Solution

by:
mightyone earned 150 total points
ID: 13604764

Your code should look somehow like this....

class A{
public String [] str = new String {"empty","full","full"};

public print(int i){
if (i > str.length){i = 0;}
System.out.println(i+"  :  "+str[i]);
}
}

class B{

private A classA = new A();
public B(){}
set(String s, int idx){
A[idx] = s;
}

public static void main(String args[]){
B classB = new B();
b.set("full",0);
b.print(0);
}}


}



if not change your array to static and it will work, but then you really have to make sure ONLY one Thrrad is manipulating your array.....
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13604811
I guess mightyone ment to write:

classA.str[iidx] = s;

instead of
>> A[idx] = s;


0
 
LVL 6

Expert Comment

by:mightyone
ID: 13604883
of course sorry for that ;-)
0
 
LVL 6

Expert Comment

by:mightyone
ID: 13604897
and change
set(String s, int idx){
A[idx] = s;
}
to

public void set(String s, int idx){
A[idx] = s;
}
0
 

Author Comment

by:m-jansen
ID: 13605065
Thanx
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses
Course of the Month11 days, 7 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question