Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Array declaration

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everyone
15. Which of these array declarations is not legal? (Choose all that apply)
A. int[][] scores = new int[5][];
B. Object[][][] cubbies = new Object[3][0][5];
C. String beans[] = new beans[6];
D. java.util.Date[] dates[] = new java.util.Date[2][];
E. int[][] types = new int[];
F. int[][] java = new int[][];

answer : C,E,F

i dont uderstand   F option .
Can anyone help me about this problem?

 
Sheriff
Posts: 7660
522
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, answers are correct.

Please explain why answer E convinces you, but not F?
 
Liutauras Vilda
Sheriff
Posts: 7660
522
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch!
 
Darya Naghiyev
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:First, answers are correct.

Please explain why answer E convinces you, but not F?



i think that E option is not legal because
in the right side  point on simple array not 2d array .
am i right ?
 
Saloon Keeper
Posts: 12165
258
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct, but there's a second reason, and that's also the same reason why F is not valid: Array instances MUST have a length. Neither E nor F has a length when you create the array.

The length of A is 5, the length of B is 3, the length of C is 6 and the length of D is 2. Passing additional lengths for nested arrays is optional. When you don't pass additional length arguments, each element of the containing array is just initialized with null.

For instance, the result of new Date[2][] is an array that looks like [null, null], where each null can be replaced with a reference to a nested array of Date.

The result of new Date[2][3] is an array that looks like [[null, null, null], [null, null, null]], where each null can be replaced by a reference to a Date instance.

Another way of looking at it:
is equivalent to
 
30 seconds to difuse a loaf of bread ... here, use this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic