Java Programming - Language Fundamentals - Discussion
Discussion Forum : Language Fundamentals - General Questions (Q.No. 6)
6.
Which three are legal array declarations?
- int [] myScores [];
- char [] myChars;
- int [6] myScores;
- Dog myDogs [];
- Dog myDogs [7];
Answer: Option
Explanation:
(1), (2), and (4) are legal array declarations. With an array declaration, you can place the brackets to the right or left of the identifier. Option A looks strange, but it's perfectly legal to split the brackets in a multidimensional array, and place them on both sides of the identifier. Although coding this way would only annoy your fellow programmers, for the exam, you need to know it's legal.
(3) and (5) are wrong because you can't declare an array with a size. The size is only needed when the array is actually instantiated (and the JVM needs to know how much space to allocate for the array, based on the type of array and the size).
Discussion:
39 comments Page 4 of 4.
Nidhin said:
1 decade ago
Please explain in detail why 4 & 5 are wrong.
Rajendra Verma said:
1 decade ago
Why first is correct ? int [] myScores [];
MurugenthiranJeya.N said:
9 years ago
Anyone, Please explain the 5th option.
Ashutosh MIshra said:
9 years ago
Can you explain how 4th is correct?
Raushan said:
1 decade ago
Why 4th option is wrong ? Explain.
Kavi said:
5 years ago
Dog is data type or not? Explain.
(1)
Madhava said:
4 years ago
Dog is a reference data type.
Amit said:
4 years ago
I think 2 4 5 is valid.
(4)
Bharathraj said:
1 decade ago
Why 5 option is wrong?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers