• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

scjp1.4 qtn on Mult-dimensional array  RSS feed

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The answer for the following question is A, B, E, and F.
Could you please any one explain, how these answers are correct?

Thank you

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;
 
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a, b, e, f is correct.
[ June 08, 2006: Message edited by: Naseem Khan ]
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how come option c is wrong while e works fine?
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C. b2[1][1][0] = b[0][0];
"b[0][0]" is byte.

F. b2[0][1] = big;
"big" is two dimensional array.
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Option C->>> required is one dimentional array but found primitive type.

Option E->>> required is primitive type type and found same.
 
lavanya sankuappan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your response guys
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

if you guys dont mind can u please explain the correct answers once again

thanks
sreelatha
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




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;


A. b2[0][1]is two dimentional array and b is also 2-D array. TRUE

B. b[0][0] is primitive byte and b3 is alos primitive byte. Same type. TRUE

C. b2[1][1][0] is one dimentional array and b[0][0] is primitive type. Incompatible type. FALSE.

D. b2[1][2][0] is one dimentional array and b is 2-D array. Incompatible type. FALSE

E. b2[0][1][0][0] is byte primitive type and b[0][0] is also byte primitive type. TRUE

F. b2[0][1] is 2-D array and big is also 2-D array. So compatible type. TRUE

regards
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a doubt here. E.g. answer E:
F. b2[0][1] = big;

b2 has already specified the sizes of its 4 dimensions.
and b2[0][1] will have size [1][2].
but big's size is [7][7] which is larger than b2[0][1].

how can 'big' fit into b2[0][1]? Or is this checked in run time but not in compile time? isn't array's size already known at compile time?
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!