Java parameter passing Method

Source: Internet
Author: User

Java parameter passing Method

If method A calls Method B and the parameter of Method B is of the basic data type, method A passes the parameter value to Method B. If the parameter of Method B is an object or an array, method A transmits A parameter reference to method B.

Example:

Public class VariableTest {

Public int membervariable = 0;

Public static void main (String [] args ){
Int param1 = 0;
VariableTest param2 = new VariableTest ();
VariableTest param3 = new VariableTest ();
Int [] param4 = {0 };
ChangeParameter (param1, param2, param3, param4 );
System. out. println ("param1 =" + param1 );
System. out. println ("param2.membervariable" + param2.membervariable );
System. out. println ("param3.membervariable" + param3.membervariable );
System. out. println ("param4 [0] =" + param4 [0]);
}

Public static void changeParameter (int param1, VariableTest param2, VariableTest param3, int [] param4 ){
Param1 = 1;
Param2.membervariable = 1;
Param3 = new VariableTest ();
Param3.membervariable = 1;
Param4 [0] = 1;
}


}

Print result:

Param1 = 0
Param2.membervariable1
Param3.membervariable0
Param4 [0] = 1




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.