the thing I would like to know is how to write an enhanced for loop for an array based on the class of the object in the array. I understand how to do a for loop based on index number like if it's odd or even but I'm looking for based on class. Example:
Array[] Kind = new Array[3];
Kind[0] = new Fruit(xxx,yyy,zzz)
Kind[1] = new Veg(xxx,yyy,zzz)
Kind[2] = new Fruit(xxx,yyy,zzz)
Kind[3] = new Veg(xxx,yyy,zzz)
Fruit and Veg classes are created and extended from the Kind class. I need to write a FOR loop that out puts something for Fruit and something different for Veg.
Kindis a class? The way you wrote it,Arrayis your class andKindis a variable name. Also, you allocated only 3 elements in your array and you're trying to assign to 4, so you will get an out-of-bounds exception. Maybe you meanKind[] array = new Kind[4];and then setarray[0] =...