Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

array passing to method - doubt

 
raja kanak
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The above code compiles fine but gives runtime exception ArrayIndexOutOfBoundsException at //1.

My doubt is
don't java pass reference to method argument?
 
Henry Wong
author
Marshal
Pie
Posts: 21387
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
don't java pass reference to method argument?


Java pass a copy of the array reference. This means that if you change the elements of the array, it will change the original array. If you change the array reference itself, it will not affect the original reference.

Henry
 
raja kanak
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The correct answer is 3. Now I got it. thanks a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic