• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Javeed Mock Exam

 
Tejas Nakawala
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tejas Nakawala
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankx,
Lori , Bill and Madhavi..
I got the point.
Tejas Nakawala
 
Vijayalakshmi Chipada
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tejas,
Can you let me know the website for Javeed Mock exam
Thank you

------------------
Ch. Vijayalakshmi
 
Tejas Nakawala
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi the like u wnt is as bellow.
http://www.javeedansar.domainvalet.com
thnkx
Tejas Nakawala
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic