Just in touch with Java, read the Ushimaki teacher's video, Java's parameter passing Way is a: "Pass value".
public class Human {
public static void swap(int iNum, int jnum)
{
int temp = INum;
INum = Jnum;
Jnum = temp;
}
public static void init(Student St)
{
Student temp = st;
St.name = "I was created in Init";
}
public static void Main (string[] args) {
TODO auto-generated Method Stub
int i = 10;
int j = 7;
Swap (I, j);
System.out.println ("i=" +i + ", j=" +j);//actually not exchanged, still i=10,j=7
Student stu1 = new Student ();
Human. Init (STU1);
System.out.println ("stu1 name =" +stu1.name);//display: I was created in Init
}
}
In Java, when an object is passed as an argument, the reference to the address should be passed correctly, so it will be modified in the Init method and printed in the Main method.
Base data type as an argument: copy a copy
Object data types as arguments: delivery of addresses (similar to C + +)
I'm just a beginner, hoping to get more knowledge in my mistakes.
Object data type as an argument