I know I can use ArrayList for this, but I don't understand why I can't add an Object intance to the following Object[] array?
class Penguin {
public void say(){
System.out.println("Hi, I am a penguin!");
}
}
public class TempTest {
private Object[] items;
private int next = 0;
private int i = 0;
public void add(Object x){
if(next < items.length)
items[next++] = x;
}
public boolean end() { return i == items.length; }
public Object current() { return items[i]; }
public void next() { if(i < items.length) i++; }
public static void main(String[] args) {
Object[] obj = new Object[5];
Object p = new Penguin();
obj.add(p);
}
}

TempTest#addnotObject[]#addaddmethod it belongs to TempTest not Object[]. My bad.