Afraid you are mistaken. There is no such thing as pass by reference in Java®.
ubey bey wrote:. . . there is such a thing as passing by value(copy) or passing by reference in Java.
I thought that line is easy to understand. There is nothing unusual about having two StringBuilder objects. I think you need to follow the execution with a pencil and note which object is pointed to by which reference. Also write down the contents of each StringBuilder.
. . . second line it also creates new stringbuilder object, this why is so confuesing.
any other explanations?
ubey bey wrote:
I dont understand why is s2 = s2b?
David Simkulette wrote:
I see what you're saying. People telling you Java is pass by reference are right. But the implications to that when the thing being passed is a non-primitive are subtle.
Dave Tolls wrote:
I think you mean "Java is not pass by reference".
Which book? Please always tell us the origin for such questions, to avoid copyright problems, and so those of us who have access to that book can read the original. Please include the page number. I hope that book doesn't say that Java® supports pass‑by‑reference.
ubey bey wrote:. . . . THe book explains about passing data by copy or by reference. . . .
its a book of Sybex
title: OCA: Oracle Certified Associate Java SE 8 Programmer I study quide.
By: Jeanne Boyarsky & Scott Selikoff
page 39 Passing data among methods.
on page 39 it explains with example wich ment for other languages like Perl.
But the author explains that Java is pass-by-value language.