Ok, i didn’t miss it out the first time - this board seems to be reading my [ i ] as an italics marker. Ok, here’s the code - please ignore the spaces in the [ i ]:
whoops i missed the "i"out there, the actual code is:
for (int i = 0; i < name.length; i++)
{
System.out.println(instrument[ i ].getName());
}
anyone know why this doesn’t work? I explained what everything is in my original post above.
public static void main( String args [ ] ) {
ins instrument [ ] = new ins [ 3 ] ;
int name [ ] = new int[instrument.length];
instrument [ 0 ] = new ins("Ins1");
instrument [ 1 ] = new ins("Ins2");
instrument [ 2 ] = new ins("Ins3");
for (int i=0; i<name.length; i++){
System.out.println(instrument [ i ].getName());
}
}
}
class ins{
String name;
public ins( String n){
this.name=n;
}
public String getName(){
return name;
}
}
Look at this code code… same as yours. It works fine and the output is
Ins1
Ins2
Ins3
Output completed (0 sec consumed) - Normal Termination
May be you’ve gone wrong somewhere else.
(again… Please ingnore the spaces near square braces)