Help with objects in ArrayList
Hi, can someone please help.
I have 4 external classes called Cat, Dog etc.
My test program instantiates them i.e. Cat cat = new Cat();
Afterwards I placed them in an ArrayList called 'animals':
I then created an enhanced 'for' loop:
The idea is to loop through each object and call its public methods.
for(Obect obj : animals)
obj.methodName(); //(The idea is that obj represents 'cat')
This creates an error. Is it even possible?
Thanks in advance.