• 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

weird statment....method call

 
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


the statement on line 1 seems weird. i thought that the code
wont compile.....because the statement doesnt male any sense.
code compiles and o/p is 2

please explain line 1

thanks in advance
nieranjan
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I thnk explanation lies in the fact that null is returned and is
perfectly acceptable as a int[] (object can be null).

Further whenever we try to access [index=2] on a null, it throws
exception and in catch you have a index value print statement, hence is
the output 2.

Does that answer your question?
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow
I didnt know we can assign the index value of the array,as in line 1 of the code posted by Niranjan. Was that a new addition in jdk 1.5 or was in the earlier versions itself!!!
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Balaji Sampath:
Wow
I didnt know we can assign the index value of the array,as in line 1 of the code posted by Niranjan. Was that a new addition in jdk 1.5 or was in the earlier versions itself!!!




Remember that an assigment statement such as index=2 is also an expression. The value of the expression is 2, the value assigned to index. The value of the expression is what is used to index the array.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic