java-parameter passing

Source: Internet
Author: User

Package com.day11. parameter passing;

public class Demo {

/**
* @param args
* Basic Data type parameter value is passed without changing the original value, because the stack is played after the call, and the local variable disappears
* The value of the reference data type is passed, changing the original value, because even if the method is bouncing but the array object of the heap memory is still there, you can continue to access the
* Both are value passing, one passing is the specific value, one is passing the address value
*/
public static void Main (string[] args) {
int a=1;
int b=2;
Change (A, b);
System.out.println ("a=" +a+ "" + "b=" +b);//a=1 b=2

Int[] arr={1,2};
Changearray (arr);
System.out.println ("arr[0]=" +arr[0]+ "" + "arr[1]=" +arr[1]);//arr[0]=2 arr[1]=1
}


private static void Change (int a, int b) {
int temp;
Temp=a;
A=b;
B=temp;
System.out.println ("a=" +a+ "" + "b=" +b);//a=2 b=1
}

private static void Changearray (int[] arr) {
int temp;
TEMP=ARR[0];
ARR[0]=ARR[1];
Arr[1]=temp;
System.out.println ("arr[0]=" +arr[0]+ "" + "arr[1]=" +arr[1]);//arr[0]=2 arr[1]=1
}
}

java-parameter passing

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.