• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, the answer is wrong.
It will cause a NullPointerException and not a compiler error.

HS
 
Ranch Hand
Posts: 817
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic