aspose file tools
The moose likes Beginning Java and the fly likes Doubt About the output of this Question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Doubt About the output of this Question" Watch "Doubt About the output of this Question" New topic
Author

Doubt About the output of this Question

Akhila Rayaprolu
Greenhorn

Joined: Jan 30, 2006
Posts: 1
Given the following,
1. public class Test {
2. public static void main(String [] args) {
3. byte [][] big = new byte [7][7];
4. byte [][] b = new byte [2][1];
5. byte b3 = 5;
6. byte b2 [][][][] = new byte [2][3][1][2];
7.
8. }
9. }
which of the following lines of code could be inserted at line 7, and still allow the code to
compile? (Choose four that would work.)
A. b2[0][1] = b;
B. b[0][0] = b3;
C. b2[1][1][0] = b[0][0];
D. b2[1][2][0] = b;
E. b2[0][1][0][0] = b[0][0];
F. b2[0][1] = big;

I would like to know the set of answers for the above question along with an explanation as to why.
karthikeyan Chockalingam
Ranch Hand

Joined: Sep 06, 2003
Posts: 259
Option C and D that is
will not compile as the assigned array dimensions are not compatible .


http://www.skillassert.com


Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12929
    
    3

If you have a computer with the JDK installed, you can find out for yourself which of the answers is correct.

A hint: Multi-dimensional arrays in Java are just arrays of arrays. So byte[][] b is an array of arrays: the entries b[0], b[1], ... are each an array of bytes (byte[]).

byte[][][][] b2 is an array of arrays of arrays of arrays.
b2[0] is a byte[][][].
b2[0][0] is a byte[][].
b2[0][0][0] is a byte[].
b2[0][0][0][0] is a byte.

Do you see it now?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Doubt About the output of this Question
 
Similar Threads
array
Array Dimensions
Multidimensional Arrays
Multidimensional arrays
Self Test Question on Arrays by Kathy's Book