Animal[] animals = new Animal[200];
animals[0] = new Animal();
animals[1] = new Cheetah();
animals[2] = new Gazelle();
animals[3] = new Animal();
animals[4] = new Cheetah();
animals[5] = new Gazelle();
animals[6] = new Animal();
animals[7] = new Cheetah();
animals[8] = new Gazelle();
for (int i = 0; i < animals.length;i++)
if (animals[i] == null) {
System.out.println("Not initialized.");
} else{
if (animals instanceof Cheetah) System.out.println("animals[" + i
+ "] is a Cheetah");
if (animals instanceof Gazelle) System.out.println("animals[" + i
+ "] is a Gazelle");
if (animals instanceof Cheetah) System.out.println("animals[" + i
+ "] is an Animal");
}
}