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

Javeed Mock Exam

Tejas Nakawala
Ranch Hand

Joined: Jan 04, 2001
Posts: 80
Hello Friends Pls Explain....
1. Which declaration for 2D array are true ?
a> int a[][] = new int[][]
b> int []a[] = new int[5][]
c> int []a[] = new int[][5]
d> int [][]a = new int[5][]

ans given are : b, d.
If I am not wrong according to me the ans is : a,d.
Pls let me clarify .....

2. What is the result of the following program if it is compiled.
class Continue {
public static void main(String args[]) {
outer: for(int i=0;i<2;i++) {

for: for (int k=0;k<2;k++) {
if (i==j) break for;
System.out.println(i+ " " +k);
}
}
}
}
Ans given is rints 10
11
According to me the code will not compile for two reasons.
1. variable 'j' is not defined .(i.e. int, byte, short..etc)
2. 'for' is the java keyword and can not be used as label.
Pls Let me sure.
Tejas Nakawala.
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
For the first one, I think the answer is A, B and D.
A will work because you don't have to initialze size.
B will work because you can initialize size for first array and not second array, and the int []a[] is awkward, but allowed
C will not work because you can't initialze the size for the inner array if you don't do the outer array.
D will work for the same reason B will work,
So I like A B and D
As for the second one, I think you are correct. j is not declared anywhere, so you are going to run into problems and for is a keyword so you can't use it.
Bill
madhuri vl
Ranch Hand

Joined: Jan 17, 2001
Posts: 86
Hi ,
For the first question my answers are a,b,d and i have a doubt on array dec.
Is this correct
int a[][]=new int[5][5];
please reply


madhuri.
Tejas Nakawala
Ranch Hand

Joined: Jan 04, 2001
Posts: 80
hi Madhavi and Bill,
Thankx for reply,
But i am still not convince for the first one.
Is for 2D array declaration like...
int []a[] = new int [][] is valid or not ?
I have never seen such declaration in any book.
If u have seen pls let me know the book name.
Can any one thorw more light on this ?
Tejas Nakawala
Lori Battey
Ranch Hand

Joined: May 17, 2000
Posts: 37
According to all I've seen, A) is incorrect. When you initialize an array with the keyword "new" you must either state the size or input the data so the space can be allocated on the heap. At declaration time you don't need the size but when instantiating, you do...


Lori Battey<br />SCJP2
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
Lori you are correct, my mistake. A is not correct as you didn't initialize the size of the array.
Try this code:

Bill
Tejas Nakawala
Ranch Hand

Joined: Jan 04, 2001
Posts: 80
Thankx,
Lori , Bill and Madhavi..
I got the point.
Tejas Nakawala
Vijayalakshmi Chipada
Greenhorn

Joined: Dec 04, 2000
Posts: 17
Hi Tejas,
Can you let me know the website for Javeed Mock exam
Thank you

------------------
Ch. Vijayalakshmi


Ch. Vijayalakshmi
Tejas Nakawala
Ranch Hand

Joined: Jan 04, 2001
Posts: 80
Hi the like u wnt is as bellow.
http://www.javeedansar.domainvalet.com
thnkx
Tejas Nakawala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Javeed Mock Exam