The Artima Developer Community
Sponsored Link

Java Answers Forum
passing arrays to another class

2 replies on 1 page. Most recent reply: Apr 19, 2004 11:31 PM by Matthias Neumair

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
billy

Posts: 1
Nickname: billy
Registered: Apr, 2004

passing arrays to another class Posted: Apr 17, 2004 6:39 PM
Reply to this message Reply
Advertisement
first of all i'd like to make it clear that i'm a java newb so please take it easy on me :]

i'm writing a class (for convenience sake lets call it Change)

i need to test this class, so i made another public class , which i'll call Tester.

the goal in this "program" is to invoke a method in Change, lets call the method : fix

so in Tester it will look something like this: Z = X.fix(Y);

whereas X, Y, Z are all arrays.

my question is how do i initiate X, Y, and Z...am i suppose to declare them as Change type? (derived from the class Change)

i'm having a real hard time with this and its killing me.

another thing i'd like to verify on is, am i suppose to write the fix method as the following : public fix (Change[] X, Change[] Y) ?

and what should the return type be on method fix, assuming i'm suppose to return an array to Z.

thx in advance! i'd be more than happy to elaborate on this if i'm confusing certain ppl!


Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: passing arrays to another class Posted: Apr 19, 2004 11:25 PM
Reply to this message Reply
If x,y,z are arrays, you can't call x = x.fix(y)
It should be something like z = x[index].fix(y)


To the question:
Declare:
Change[] x = new Change[sizeX];
Change[] y = new Change[sizeY];
// fill them with values: x = new Change(...);
Change[] z;

public Change[] fix (Change[] x, Change[] y) {
Change[] returnVal = new Change[returnSize];
// do something useful
return returnVal;
}

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: passing arrays to another class Posted: Apr 19, 2004 11:31 PM
Reply to this message Reply
Correction:

//fill them with values: x[index] = new Change(...);

Flat View: This topic has 2 replies on 1 page
Topic: cannot retrieve some methods from xerces.jar Previous Topic   Next Topic Topic: Problem in JTable.. pls help me..

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use