amolpalekar kadolkar wrote:I am really confuse when passing the objects from sender to receiver
Q1) In which scenario receiver and sender will refer to same object?When receiver makes an changes when it reflects orginal copy in sender.
When pass object reference to a method, it means you pass the bit
pattern of the variable. So that particular object is referenced(at least) by two referenced variables. One from your previous method, and the second from from the method, to which you pass the reference of that object. So, you can change the state of that object using either of the references. But if you pass primitive variables, because primitive variable's bit pattern holds the values you assigned to that primitive variable(For example, int b = 9;) here, in the bit pattern of b holds 9. So when you pass this bit pattern to methods, it means you pass that value(in this case, you pass 9), if you change them in the calling method, it won't reflected to called method.
Try this,
For Strings, because of the String Literal Pool, the story is different.