Example One
ClassDemo{PublicIntTemp=30;}PublicClassT{PublicStaticvoidMain(String[]Args){TODO auto-generated Method StubDemoD1=NewDemo();D1.Temp=50;System.Out.println(Before the "Fun () method call:"+D1. Temp); Fun(d1); System. Out. println("fun () after method call:"+d1. Temp); } public static void fun(Demo D2) { D2. Temp = +; } }< /c18>
Memory analysis
Example Two
PublicClassT{PublicStaticvoidMain(String[]Args){TODO auto-generated Method StubStringStr1="Hello";System.out. ( "Fun () method call before:" +str1); span class= "n" >fun (str1system.. ( "Fun () method call before:" +str1); Span class= "O" >} public static void fun (string s2) {s2 = "mldn" } /span>
Memory analysis
Example Three
ClassDemo{StringTemp="Hello";}PublicClassT{PublicStaticvoidMain(String[]Args){TODO auto-generated Method StubDemoD1=NewDemo();D1.Temp="World";System.Out.println(Before the "Fun () method call:"+D1. Temp); Fun(d1); System. Out. println("fun () after method call:"+d1. Temp); } public static void fun(Demo D2) { D2. Temp = "Mldn"; } }< /c18>
Memory analysis
This procedure is exactly the same as the process of example one, and example two is special, because string is a special class whose contents cannot be changed.
Copyright NOTICE: This article uses the BY-NC-SA agreement to authorize, reproduced the Wheat Field Technical blog article please indicate the source
Original address: Http://itmyhome.com/2015/03/java-study-notes-passed-by-reference
Java Learning Note 15--Reference delivery