Yes, Java is pass by value only. But the confusing thing is that references are also passed by value.
For more information, see this JavaRanch Campfire Story: Pass-by-Value Please
i am confused about the java's concept of pass by value ............as some books say java is all pass by value
and some says Primitive types are passed by value and
Objects are passed by reference
In which book did you find that Objects are passed by reference
It's actually object references are passed by value and not objects.
Hope this helps
Well done. This is a common problem, and causes quite a lot of confusion, particularly when some books are not precise in how they describe it.
Originally posted by suavedeep kaur:
Thanks sir i got my doubt cleared
Click the search button above, and put "pass by value" in the box. You get lots of links; try this one, and look at the "wonderful link" quoted in the 3rd message. It is a bit complicated, but explains very clearly what pass-by-reference would be and how in works in Pascal. You can then try it out in Java, as in Michael Dunn's example, and you can see how the results are different.