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 3 of 4.
Guru said:
1 decade ago
4 is not correct you can verify by making program and declare like this.
Annon said:
1 decade ago
As we create our own data type in c, here also we can create the same.
Jit said:
7 years ago
4 is valid because Dog is a user data type created by the user.
Haftu M said:
7 years ago
A is correct, according to the fundamental array declaration.
Sarita goswami said:
8 years ago
Dog is not variable. So how can you say 4 option is correct?
Prameela said:
7 years ago
Can anyone explain the creation of own data type in Java?
Arjunkulothungan said:
7 years ago
Can anyone please explain how to create an own datatype?
Thasnim said:
1 decade ago
Please explian why an array can't declare with size?
Vignesh said:
8 years ago
Why 4 is correct?
It does not have any data type.
It does not have any data type.
Satya cheemarla said:
1 decade ago
How the 4th answer is correct and why 5 is wrong?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers