Administrator
|
Your description of arrays is fine, but your description of objects isn't even particularly close.
An object is not an "array of arrays". Like an array, it is a block of memory somewhere on the heap and you access it by means of a pointer whose value is the address of the first word in that block (the block's base address).
So say we have an object that has five words in its block. We need someway of accessing those five words individually, and so we give them names. We associate the field variable 'bob' with the first word, 'sue' with the second word and so on. The compiler is responsible for keeping track of the offset of each declared field variable relative to the beginning of the block and when we reference that variable the offset is added to the block's base address.
We have the exact same issue with an array. If we have an array consisting of five words, we need some way of accessing those words individually. But because an array has the constraint that it must consist of a collection of the same type of variable, we can associate an index value with each word and calculate the address given the index and the base address -- we use the notation myArrayName[index] to give the compiler the needed information.
So an array is simply a special kind of object that allows a simpler and cleaner, but less flexible, means of accessing the individual elements.
|