The Artima Developer Community
Sponsored Link

Java Answers Forum
java objects passed by referance

1 reply on 1 page. Most recent reply: Aug 7, 2002 6:16 AM by Don Hill

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
kaushik

Posts: 1
Nickname: kalok2
Registered: Aug, 2002

java objects passed by referance Posted: Aug 7, 2002 5:48 AM
Reply to this message Reply
Advertisement
Hi, I have a problem here,
The code is this please tell me what is problem with java objects passed by ref.

class test
{
public static void main(String[] args)
{
String str="Some String Msg.";
System.out.println("before method call test1 .."+str);
test1(str);
System.out.println("after method call test1 .."+str);
}

public static void test1(String str)
{
str="some new string masg here..";
System.out.println("......."+str);
}
}
why String object is not changing after the method test1 called.


Don Hill

Posts: 70
Nickname: ssswdon
Registered: Jul, 2002

Re: java objects passed by referance Posted: Aug 7, 2002 6:16 AM
Reply to this message Reply
Strings are not mutable, they can't be change, a new string has been created when you do this and you loose the ref to the string that was passed in.

for more info check the API java.sun.com

Flat View: This topic has 1 reply on 1 page
Topic: Argument Passing Previous Topic   Next Topic Topic: could anyone help me to solve this problem

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use