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 Question 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 Question" Watch "Array Question" New topic
Author

Array Question

thejaka samarakoon
Ranch Hand

Joined: Jul 20, 2010
Posts: 56


Can somebody explain How the answer to this question becomes" 15 15" ?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

thejaka samarakoon wrote:

Can somebody explain How the answer to this question becomes" 15 15" ?

you are passing copy of the reference of a1 to a method called fix, there you are modifying the object array[which referenced by a1] by using the copy of reference a3 then assign to the object array to reference a2. so now a2 and a1 both reference to the existing array object. hence the result.

hope this helps
Ikpefua Jacob-Obinyan
Ranch Hand

Joined: Aug 31, 2010
Posts: 394

The fix() method changes the value of the second element of the array to 7 so you now have Then the println statements displays the total sum of the values of the elements, which is equal to 15 15. If you want individual elements to be displayed then modify the println statement as follows:

Output:


I hope this helps

Regards

Ikpefua


OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
thejaka samarakoon
Ranch Hand

Joined: Jul 20, 2010
Posts: 56
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Array Question
 
Similar Threads
kathy sierra question
What's the answer?
doubt regarding the output??
Passing an Array Reference
passing arrays