![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: May 2006
Posts: 39
Rep Power: 0
![]() |
passing variables from one method to another?
public class something
{
public void methodOne()
{
int i = 0;
int x = 4;
String word = "hello";
int[] abc = new int[26];
while( i < 26)
{
abc[i] = x;
x++;
i++;
}
methodTwo(i, x, word, abc);
}
public void methodTwo(i, x, word, abc)
{
int a = i;
int b = x;
String c = word;
int d = abc;
}
} |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Apr 2006
Posts: 136
Rep Power: 0
![]() |
methodTwo doesn't have any variable types declared.
[PHP] //this works public class something { public void methodOne() { int i = 0; int x = 4; String word = "hello"; int[] abc = new int[26]; while( i < 26) { abc[i] = x; x++; i++; } methodTwo(i, x, word, abc); } public void methodTwo( int i, int x, String word, int abc[]) { int a = i; int b = x; String c = word; int d[] = abc; } } [/PHP] btw, please work at the issue before posting, these are common program errors and it shows us that you do not know what you are doing. I advise you to read up so references. |
|
|
|
|
|
#3 |
|
Programmer
Join Date: May 2006
Posts: 39
Rep Power: 0
![]() |
yeah, thanks, I noticed.
I have been a little jumpy recently... |
|
|
|
|
|
#4 |
|
Programmer
Join Date: May 2006
Posts: 39
Rep Power: 0
![]() |
well I just have hit another stumbling block, I can't invoke a method that has a passed array within its argument.
like if I have: public void initAbc(){
String[] abc = new String[7];
//destinations within array
abc[0] = "[1] fasd";
abc[1] = "[2] fdas";
abc[2] = "[3] dfafsd";
abc[3] = "[4] Hedfrmes";
abc[4] = "[5] dfas";
abc[5] = "[6] dfas";
abc[6] = "[7] asdfasfds";
printDestinations( abc );
}
public void printAbc( String abc[] )
{
int i = 0;
while ( i < 7 )
{
System.out.println(abc[i]);
i++;
}
}if I try to invoke it in another class, for instance: classSomething abc = new classSomething(); abc.initAbc(); abc.printAbc(); <-- doesn't work. |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Apr 2006
Posts: 136
Rep Power: 0
![]() |
First of all, it doesn't work because printAbc() contains arguments and to me it looks like it doesnt have any arguments! And doesn't initAbc() call printtAbc automatically?
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|