Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question "Declare long arrays" in MasterExam downloadable free with purchase of S&B

 
Dave Alkire
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something went totally wrong with this question, "What is the result?". You can see that this compiles fine despite their claim, but instead there's a runtime exception:

:roll:
 
H Singh
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the answer is wrong.
It will cause a NullPointerException and not a compiler error.

HS
 
amit taneja
Ranch Hand
Posts: 813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
error will be due to accessing a[1][0]; ?

becuase thee is no element in the sub-array ?
 
Dave Alkire
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
becuase thee is no element in the sub-array ?


Yeah, I think it's that the second dimension is declared but not initialized; that is, the compiler doesn't care because it knows that there's an array of longs, but then the jvm gets confused because it doesn't know how many there are supposed to be; so it's trying to use something that hasn't been fully defined.
[ June 08, 2005: Message edited by: Dave Alkire ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic