Originally posted by Ravinder Singh:
Line 6:
two dimension int array a assigned to an Object d2 --> code compiles
Line 7:
two dimension int array a assigned to a single dimension Object array d3 --> code compiles
Line 8:
two dimension int array a assigned to double dimension Object array d4 --> compiler error!
Q. Why does the code compiles with respect to line 6 and line 7 and NOT for line 8? What are the differences?
The variable "a" is an array of array of ints.
Remember that an array is an object -- it inherits from object -- so...
- The variable "a" is also an object.
And this can also be further applied as...
- an array of ints is also an object.
hence...
- The variable "a" is also an array of objects.
And finally...
- The variable "a" is not an array of array of objects. It is an array of arrays of ints.
Henry