
11-04-2009, 05:17 PM
|
|
Member
|
|
Join Date: Nov 2009
Location: Colombo, Sri Lanka
Posts: 22
Rep Power: 0
|
|
Java Array Assignments?
Given:
|
Code:
|
byte[] array1, array2[];
byte array3[][];
byte[][] array4; |
If each array has been initialized, which statement will cause a Compiler Error?
Give me the answer and the reasons. Thanx n advanced!
1) array2 = array1;
2) array2 = array3;
3) array2 = array4;
4) Both 1 & 2.
5) Both 1 & 3.
6) Both 2 & 3.
Last edited by abimaran; 11-04-2009 at 05:21 PM.
|
|

11-04-2009, 05:25 PM
|
|
Senior Member
|
|
Join Date: Sep 2008
Location: Voorschoten, the Netherlands
Posts: 3,337
Rep Power: 5
|
|
|
Homework?
kind regards,
Jos
|
|

11-04-2009, 05:26 PM
|
|
Member
|
|
Join Date: Nov 2009
Location: Colombo, Sri Lanka
Posts: 22
Rep Power: 0
|
|
|
No, JosAH. I'm preparing for SCJP 6 exam.
|
|

11-04-2009, 05:34 PM
|
|
Senior Member
|
|
Join Date: Sep 2008
Location: Voorschoten, the Netherlands
Posts: 3,337
Rep Power: 5
|
|
Originally Posted by abimaran
|
|
No, JosAH. I'm preparing for SCJP 6 exam.
|
Well, count the number of dimensions for each array and see for yourself.
kind regards,
Jos
|
|

11-04-2009, 05:36 PM
|
|
Member
|
|
Join Date: Nov 2009
Location: Colombo, Sri Lanka
Posts: 22
Rep Power: 0
|
|
|
Can we assign one Dimentional array into 2 - Dimentional array and we've to assign every member of one array to other by using a loop?
Here??
Last edited by abimaran; 11-04-2009 at 05:39 PM.
|
|

11-04-2009, 05:38 PM
|
|
Senior Member
|
|
Join Date: Aug 2009
Posts: 2,193
Rep Power: 4
|
|
Originally Posted by abimaran
|
...
Give me the answer and the reasons. Thanx n advanced!
...
|
What is your answer and what are your reasons?
|
|

11-04-2009, 05:41 PM
|
|
Member
|
|
Join Date: Nov 2009
Location: Colombo, Sri Lanka
Posts: 22
Rep Power: 0
|
|
|
The answer should be within those 6 answers.
|
|

11-04-2009, 06:00 PM
|
|
Senior Member
|
|
Join Date: Sep 2008
Location: Voorschoten, the Netherlands
Posts: 3,337
Rep Power: 5
|
|
Originally Posted by abimaran
|
|
The answer should be within those 6 answers.
|
Of course; otherwise you would've gotten lots of replies telling you that the correct answer wasn't in the list. btw, have you been a victim of the ferocious brain eater? Is it still hungry? What do you think the answer is?
kind regards,
Jos
|
|

11-04-2009, 06:15 PM
|
|
Member
|
|
Join Date: Nov 2009
Location: Colombo, Sri Lanka
Posts: 22
Rep Power: 0
|
|
|
array1 is 1D array and array2, array3, array4 are 2D arrays. In JAVA, declaring an array means it(JAVA) creates a variable with a reference to an array. All arrays are technically 1D arrays, Multi dimensional arrays are arrays of arrays.
So, Can we assign 1D array variable into 2D array variable?
|
|

11-04-2009, 06:18 PM
|
|
Senior Member
|
|
Join Date: Sep 2008
Location: Voorschoten, the Netherlands
Posts: 3,337
Rep Power: 5
|
|
Originally Posted by abimaran
|
array1 is 1D array and array2, array3, array4 are 2D arrays. In JAVA, declaring an array means it(JAVA) creates a variable with a reference to an array. All arrays are technically 1D arrays, Multi dimensional arrays are arrays of arrays.
So, Can we assign 1D array variable into 2D array variable?
|
Suppose the first line isn't yelled at by the compiler, what is the second line supposed to do?
|
Code:
|
int[][] array2d= new int[42]; // assign a 1d array to a 2d ref.
array[1][1]= 54; // where should this be stored? |
kind regards,
Jos
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT +2. The time now is 05:21 AM.
|
|