KIO
Kreative Ideen online

Arrays are always objects, whether they’re declared to hold primitives…
int[] nums;
nums = new int[3];
nums[0] = 4;
nums[1] = 32;
nums[2] =21;

or object references.
Dog[] arrdog = new Dog[2]
arrdog[0] = new Dog();
arrdog[1] = new Dog();


But you can have an array object that’s declared to hold primitive values. In other words, the array object can have elements which are primitives, but the array itself is never a primitive. Regardless of what the array holds, the array itself is always an object!

Every element in an array is just a variable. In other words, one of the eight primitive variable types (think: Large Furry Dog) or a reference variable. Anything you would put in a variable of that type can be assigned to an array element of that type. So in an array of type int (int[]), each element can hold an int. In a Dog array (Dog[]) each element can hold… a Dog? No, remember that a reference variable just holds a reference, not the object itself. So in a Dog array, each element can hold a remote control to a Dog.

Leave a Reply

Your email address will not be published. Required fields are marked *