Java Learning Note 15--Reference delivery

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.