-1

Ok so the code i have is

public static void showCenter(ArrayList<TestPoly2> array){
        for(int i = 0; i < array.size(); i++){
            System.out.println(array.center());
        }
    }

I'm not sure how to go about this problem but this is what I have come up with from sitting here thinking.

.center() 

is a method from the superclass

I want to be able to create multiple objects from multiple different classes and store them in the same arraylist if this is possible.

Any pointers or tips are helpful : )

1 Answers1

0

Try using a foreach type loop

for (TestPoly2 elem : array) {
   System.out.println(elem.center());
}

this is of course the same result as doing a traditional loop

for(int i = 0; i < array.size(); i++){
    System.out.println(array.get(i).center());
    // or
    // TestPoly2 elem = array.get(i);
    // System.out.println(elem.center());
}
Scary Wombat
  • 44,617
  • 6
  • 35
  • 64