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 Reference

 
Richard Rex
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to all ranchers,

I'm just confused, I found this question from the Java Rule Round-Up Exam.

(#8) When you pass a reference to an array as an argument to a method call, you pass a NEW reference to the original array.

I answered false, because I think that it's not a NEW reference being passed but only a COPY of the reference. But it says its TRUE. But when I look at the explanation, it says "An array is an object, and Java always passes a COPY of the reference to the original object. Both references now point to the same array object." And I agree with the explanation, however, why is it TRUE?

I'm just really confused. Can anybody point out what I am missing out here?

Thanks!
 
Ronnie Ho
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A copy of the reference is indeed a NEW reference, the object that it refers to is the same as the original one, but the reference itself is indeed new. The point of that question is "Copy of the reference is passed", not the reference itself, that's what it means by "New". Hope it helps.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic