File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes array passing to method - doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "array passing to method - doubt" Watch "array passing to method - doubt" New topic
Author

array passing to method - doubt

raja kanak
Ranch Hand

Joined: Oct 18, 2006
Posts: 135

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

My doubt is
don't java pass reference to method argument?


live
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18760
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
raja kanak
Ranch Hand

Joined: Oct 18, 2006
Posts: 135

The correct answer is 3. Now I got it. thanks a lot.
 
Don't get me started about those stupid light bulbs.
 
subject: array passing to method - doubt