Interview Review = internal skills (2 )? Value transfer or reference: Restores when the input parameter changes to the output parameter.

Source: Internet
Author: User

I. review some typical Java value transfer and address (reference transfer) problems.

In Java, is there only one-value transfer method or two methods: value transfer and reference transfer. So far, it is still not a confirmation issue, and most of the controversial issues do not necessarily require confirmation. However, the people we learn must understand the relationship and make accurate judgments, use, and read the transfer in the program.

The following is an example:

Package net. mldream. day2; Class valhold {public int I = 10;} public class obparm {public static void main (string [] ARGs) {// todo auto-generated method stubobparm o = new obparm (); O. amethod ();} public void amethod () {int I = 99; valhold v = new valhold (); V. I = 30; another (V, I); system. out. print (v. i);} // end of amethodpublic void another (valhold V, int I) {I = 20; V. I = 20; valhold VL = new valhold (); V = VL; system. out. print (v. i); system. out. print (I);} // end of another}

The result of this program is: 10020

A simple summary: The value transfer is of course equivalent to passing the value size of the real parameter to the form parameter without modifying the original space memory, real parameters and form parameters are two different buckets. Therefore, modifications to the form parameter within the function cannot change the value of the original real parameter variable.

The so-called reference transfer can be understood as the transfer of a piece of space, the first address of a Data Structure (storage block) (because the first address often represents a piece of space memory ), it usually contains the principle that, when a function is inside, it changes, and the function is restored after it is introduced. That is, change in progress and restore in return.

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.