John Lerry wrote:
In my opinion it is not correct because the array b2, in that position, would require a 2-dimensional array and b is an array in 4 dimensions (each reference points to another array in 4 dimensions).
John Lerry wrote:In my opinion it is not correct because the array b2, in that position, would require a 2-dimensional array and b is an array in 4 dimensions (each reference points to another array in 4 dimensions).
John Lerry wrote:
- "b" array: it is a 2-dimensional array consisting of 2 other arrays, arrays are 4-dimensional array, each array refers an 4-dimensional array.
- "b2" array: it is a 4-dimensional array consisting up of 4 2-dimensional array, each array refers an array in 3 dimensions, which refers an 2-dimensional array that refers an further 2-dimensional array.
John Lerry wrote:- "b" array: it is a 2-dimensional array consisting of 2 other arrays, arrays are 4-dimensional array, each array refers an 4-dimensional array.
- "b2" array: it is a 4-dimensional array consisting up of 4 2-dimensional array, each array refers an array in 3 dimensions, which refers an 2-dimensional array that refers an further 2-dimensional array.
Is it correct?
John Lerry wrote:I tried to make a drawing to outline the concept.
is that correct?
Henry Wong wrote:
Now, can you draw it after ... is executed?
Henry
John Lerry wrote:
the problem is precisely that. ok, b is a 2-dimensional array as well as require at b2 [1] [1], the problem is that 2-dimensional array is composed of two arrays each with 2 elements, and b consists of two arrays from 4 elements.
I try to give me an answer.
In that case is not important the number of elements in the array because will have a reference to another array, then a memory address, the important thing is that it is a 2-dimensional reference.
Is it correct?
John Lerry wrote:In that case is not important the number of elements in the array because will have a reference to another array, then a memory address, the important thing is that it is a 2-dimensional reference.
Is it correct?
Henry Wong wrote:Give me a minute. I will draw the result for you... Attached
Roel De Nijs wrote:
And as you probably already know: every array is an object. And you can cast an object to an array as well. What do you think the output of this code will be (and why)?
John Lerry wrote:line 2 should be:
Is that correct? If it is correct, I believe that there will be an error in compile time rather than in runtime because the problem is on the reference.
after the change should not be any error and the output should be 4.
John Lerry wrote:
line 2 should be:
Is that correct? If it is correct, I believe that there will be an error in compile time rather than in runtime because the problem is on the reference.
after the change should not be any error and the output should be 4.
Roel De Nijs wrote:
And as you probably already know: every array is an object. And you can cast an object to an array as well. What do you think the output of this code will be (and why)?
John Lerry wrote:But the reference of type Object can have ONLY this form?
John Lerry wrote:I think there is a mistake in the cast because it refers to an array of 3 short and instead the cast tries to turn it into an array of arrays of short, generating a ClassCastException at runtime.
The correct line would be:
and then the output will be 3
is that correct?
John Lerry wrote:or the error would still been at runtime because that statement is syntactically correct?
Henry Wong wrote:
John Lerry wrote:or the error would still been at runtime because that statement is syntactically correct?
Well, does an array of short implicitly cast to an array of array of short? ... because that would be needed in order for that line to compile.
Henry
Roel De Nijs wrote:And when you have answered Henry's question, what do you think about these code snippets? Will they compile? Or do you get a runtime exception? Or ...?
John Lerry wrote:I think the cast is actually needed because the type is the same (short) but the structure is different (array vs array of arrays), I hope I do not make mistakes.
Then the correct line should be:
Is that correct?
John Lerry wrote:snippet1 compile, snippet2 does not compile due to an error in compiling the line 5.
John Lerry wrote:Can you help me to understand the graphical representation of "array" in this code?
John Lerry wrote:
if this is a correct graphical representation of the array arr.
John Lerry wrote:if this is a correct graphical representation of the array arr.
Roel De Nijs wrote:
Have another try!
John Lerry wrote:Is correct this drawing? And also the consideration of the size and number of elements.
John Lerry wrote:Is it correct this time?
Henry Wong wrote:Another small remark, that is not yet mentioned. In the second row, the second array element, the second element on that array, is a box with nothing (and no arrows coming out of it). That box should be marked as null.
Consider Paul's rocket mass heater. |