![]() |
![]() |
![]() |
![]() |
![]() |
|
So far, for simplicity, the sample arrays contain Integer instances.
You can just as easily create and use arrays of instances of other classes.
The following, for example, contrasts the creation of an array of
Integer instances with the creation of an array of Food
instances:
Array with: 570 with: 720 with: 640 with: 720
Array with: Vegetable new
with: Dairy new
with: Meat new
with: Grain new
Neither array cares what you put into it, and you need not put instances of the same class at every location in the array. The second array has instances of four different classes in it.