1. Create students class-----//Main Construction Object
http://vipnoon.blog.51cto.com/7589908/1792786
2. Create a Calc class---------//main construction method
public class Calc {public void calc1 (int num) {num = num + 1;} public void Calc2 (students stu) {Stu.setage (Stu.getage () +1);}}
3, create the Calcdemo class-----//Pass the parameter
public class Calcdemo {public static void main (string[] args) {//calc c = new Calc (); int n = 8; C.calc1 (n); students Stu = New students (); Stu.setage (+); c.calc2 (Stu); System.out.println (Stu.getage () + "\ n" +n);}}
4. Effect verification
19
8
5. Discussion
Basic data types and reference data types differ when you pass a parameter
N Num Stu Student
Memory 8 Address Replication 8+1 18 address delivery 19
Base data type, the action passes the value of the variable, and changing the value of one variable does not affect the value of the other variable.
Reference data types (classes, arrays, and interfaces), assignment is a reference to the original object (which can be understood as a memory address) passed to another reference.
String is the number of char types, and string is the reference data type.
This article is from the "Advanced Technology" blog, so be sure to keep this source http://vipnoon.blog.51cto.com/7589908/1792819
Java Method Pass Parameter