Is there anyway of doing this?
Im trying to have an array of classes and each of them has a function named run which acts differently for each class. i want them to run their version of the run function in the order they were added to the array. heres a simplified version that im trying to get working first before i write out the whole program.
class test
{
publicstaticvoid main(String[] args){
test2 tt =new test2;
}
}
class test2
{
private test2[] chap =new test2[3];
publicvoid test2(){
for(int i = 0; i<=2 ; i++)
{
chap[i] =new stuff();
}
for(int i = 0; i<=2 ; i++)
{
chap[i].run();
}
}
class stuffextends test2
{
publicvoid run()
{
System.out.println("Hello World!");
}
}
}
Sorry about the indentation.
This code gives the error
test2.java:11: cannot find symbol
symbol: method run()
location:class test2
chap[i].run();
1 error
thanks in advance,
Spoonly.
[2178 byte] By [
Spoonlya] at [2007-10-2 6:38:22]

oh right thanks a million.
now its compiling but when i run it nothing happens. it just runs and finishes and theres no output. anything else i should be doing? do i have to specify that i want it to override the original run function or something like that?
Thanks again,
Spoonly
yeah. why? should it be working now?
the only change ive made from the code above is that i added
public void run(){}
to test2.
then i compiled it all and ran it and theres no errors but nothing gets put out.
thanks for all the help so far.
You are welcome.
I just noticed the problem.
It doesn't work because this:
public void test2() { ... }
is NOT a constructor. So, Java makes its own default no-args do-nothing constructor.
Try taking out the word "void" to change that to a constructor. That might give you recursion problems. If so, put back void and change the name to something else:
public void runAll() { ... }
Then, it test main, do this:
test2 tt = new test2();
tt.runAll();
MLRona at 2007-7-16 13:46:27 >
