Similar to the method of passing function parameters in C + +, Java has 3 kinds of parameter passing methods because there is no concept of pointers in the language system, and there are only two types of java. Here is a little bit of my experience:
are: reference type passing and basic data type delivery. Reference passing is essentially not a newly created object, but instead declares another reference to point to the same object. The parameter pass for the base data type is the value pass, and the other copy is copied in memory. Here is the code explanation:
1 PackageASGH;2 3 Public classRefdemo {4 5 Public Static voidMain (string[] args) {6 Student Zs;7zs=NewStudent ();8Zs.name= "Zhangsan";9 A (ZS);Ten System.out.println (zs.name); One A int[] arr=New int[] {1,2,3,4,5,6}; - B (arr); -System.out.println (arr[0]); the - inti=100; - intj=200; - c (i,j); +System.out.println (i+ "" +j); - + } A at Public Static voidCintIintj) { - intTemp=0; -temp=i; -I=J; -j=temp; - in } - to Public Static voidbint[] arr) { +arr[0]=300; - the } * $ Public Static voidA (Student zs) {Panax NotoginsengZs.name= "Lisi"; - the } + A } the + classstudent{ - String name; $ intAge ; $ String address; -}
A summary of two ways to transfer function parameters in Java