Accessing array of method
Hi.
I was wondering how do I access whole bunch of array of method.
tom is an array of object.
Code :
Student[] tom = new Student[10];
for(int i = 0; i < 10; i++){
tom[i] = new Student();
}
Code :
tom[].accessMethod(); //Not working
Error Message: class expected and ; expected .What to do?
Re: Accessing array of method
Which element is tom[]?
compare to tom[i] = new Student() where tom[i] = the ith element in tom
Re: Accessing array of method
I mean. I want to pass the entire array into the method. Is it possible? Like : tom[1 to 100] array <--I know it's wrong but it's for illustrate purpose only.
Re: Accessing array of method
You're asking a couple different things.
Do you want to pass the entire array into a method? Then you just pass the tom variable like you'd pass any other variable.
Do you want to access a method of each instance of Student in your tom array? If so, iterate over the list an access it like so:
someArray[someIndex].someMethod();