File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Khalid Mock Exam Array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Khalid Mock Exam Array" Watch "Khalid Mock Exam Array" New topic
Author

Khalid Mock Exam Array

Gaurav Chikara
Ranch Hand

Joined: Jun 09, 2000
Posts: 410
Hi All
Which code fragments will succeed in initializing a two-dimensional array named tab with a size that will cause the expression tab[3][2] to access a valid element?
CODE FRAGMENT A:
int[][] tab = {
{ 0, 0, 0 },
{ 0, 0, 0 }
};
CODE FRAGMENT B:
int tab[][] = new int[4][];
for (int i=0; i<tab.length; i++) tab[i] = new int[3];>
CODE FRAGMENT C:
int tab[][] = {
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0
};
CODE FRAGMENT D:
int tab[3][2];
CODE FRAGMENT E:
int[] tab[] = { {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0} };
a.Code A
b.Code B
c.Code C
d.Code D
e.Code E
I do not know the correct answers for it
Please help


SCJP,SCWCD,SCBCD<br />If Opportunity doesn't knock then build the door
pardha
Greenhorn

Joined: Jun 18, 2000
Posts: 11
I guess answer is "E" ,you require 4 arrays of 3 elements each.
E declares and initialises correctly.
Correct me ,If I am wrong.
latha
Greenhorn

Joined: Jul 17, 2002
Posts: 14
Yaa, I agree with Pardha.
The answer is E. To access tab[3][2] elament, tab[][] should have min of [4][3] array.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Khalid Mock Exam Array