Java Programming - Language Fundamentals - Discussion
Discussion Forum : Language Fundamentals - General Questions (Q.No. 3)
3.
Which will legally declare, construct, and initialize an array?
Answer: Option
Explanation:
The only legal array declaration and assignment statement is Option D
Option A is wrong because it initializes an int array with String literals.
Option B is wrong because it use something other than curly braces for the initialization.
Option C is wrong because it provides initial values for only one dimension, although the declared array is a two-dimensional array.
Discussion:
18 comments Page 2 of 2.
Khushbu ahuja said:
1 decade ago
I think option D should be correct as,
int a[3][3] = {1,2,3,4}
Than by default all other elements will be null.
int a[3][3] = {1,2,3,4}
Than by default all other elements will be null.
(1)
Deep Vakharia said:
10 years ago
@Puru.
C is Incorrect because 2d Array is not being initialized as the way they have give.
C is Incorrect because 2d Array is not being initialized as the way they have give.
Pooja said:
1 decade ago
@Sonee Guptha.
int ar[2][3]= {1,1,1,2,2,2};
Is this 2d? 2d requires double braces right?
int ar[2][3]= {1,1,1,2,2,2};
Is this 2d? 2d requires double braces right?
(1)
Abhishek bhardwaj said:
1 decade ago
Answer b is wrong because of absence of curly braces in array element declaration.
Mohammadi said:
9 years ago
@Sonee Gupta.
I agree with your answer. That's the right method.
I agree with your answer. That's the right method.
(1)
Zany said:
1 decade ago
int ar[][] = {{1,2,3},{3,4,5}}; is 2d array initialization.
Vikasku652 said:
1 decade ago
How to initialize a 2 dimensional array ?
Puru said:
1 decade ago
I don't understand why C is incorrect?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers