When passing parameters in function calls in Java,
* If the passed Java data type is based on the basic type, all values are passed.
For example, eight basic data types: int, float, double, long, Char, byte, short, and Boolean correspond to integer, float, double, long, String, byte, short, and Boolean respectively.
In addition, the array is also a pass value, which is different from the C/C ++ (verify the byte array)
* If it is a common class object, it is a reference.
TestCode:
Package string;/*** test the function parameter passing value in Java. * pass the value and reference. * function parameters include common types and objects. * When passing parameters in a function call, * If the passed Java data type is based on the basic type, all values are passed. for example, eight basic data types: int, float, double, long, Char, byte, short, and Boolean correspond to integer, float, double, long, String, byte, short, and Boolean respectively. * if it is a common class object, it is a reference. * @ author zhankunlin **/public class testtransfvaluefunction {/*** test the string type. * string corresponds to Char of the basic type. */private void teststring () {system. out. println ("test string"); string src = new string ("world"); system. out. println (SRC); procsstring (SRC); system. out. println (SRC);}/*** SRC * @ Param SRC */private void procsstring (string SRC) {SRC + = "hello ";} /*** test the integer type. * integer corresponds to the basic type Int. */private void testinteger () {system. out. println ("test integer"); integer src = new INTEGER (500); // integer src = 500; system. out. println (SRC); procsinteger (SRC); system. out. println (SRC);}/*** the processing parameter SRC * @ Param SRC */private void procsinteger (integer SRC) {SRC ++ = 500;} In this method ;} /*** test the float type. * float corresponds to the basic type float. */private void testfloat () {system. out. println ("test float"); float src = new float (123.45); system. out. println (SRC); procsfloat (SRC); system. out. println (SRC);}/*** the processing parameter SRC * @ Param SRC */private void procsfloat (float SRC) {SRC ++ = 500.00;} In this method ;} /*** test parameters are common class objects. * A reference is passed. */private void testt () {system. out. println ("test common Class Object"); t src = new T (); SRC. num = 100; SRC. STR = "hello"; system. out. println (SRC. STR + "," + SRC. num); procst (SRC); system. out. println (SRC. STR + "," + SRC. num);}/*** the processing parameter SRC * @ Param SRC */private void procst (t src) {SRC. num = 500; SRC. STR = "Hello World";} public static void main (string [] argv) {testtransfvaluefunction test = new testtransfvaluefunction (); test. teststring (); test. testinteger (); test. testfloat (); test. testt () ;}} class t {Public String STR; Public integer num; Public void setstr (string Str) {This. STR = STR;} Public String getstr () {return this. STR;} public void setnum (integer num) {This. num = num;} public integer getnum () {return this. num ;}}
Running result:
Test stringworldworld test integer500500 test float123.45123.45 test common Class Object hello, 100 Hello world, 500