In the eighth article posting, the author introduces the basic knowledge that the method body must understand, and the beginner can practice it by writing a simple example. In the course of practice, we can not put all the code in the main method, Java class must have more or less method members, call these methods will be necessary steps. When a method member is invoked, if the method has arguments, it must pass the actual argument to the formal argument of the method. So it is necessary to understand the value transfer in the Java language.
The data types in Java are divided into two categories, basic data types and reference types. Therefore, the value transfer characteristics of the two data types are also introduced in this paper.
1. Value delivery of the base data type: The base data type passes a value.
The following procedure:
Package com.csst.test;
public class Test5 {
/**
* @param args
*
/public void Printx (int x) {
+ +;
System.out.println ("printx:x=" +x);
}
public static void Main (string[] args) {
//TODO auto-generated method stub
Test5 test5=new Test5 ();
int x=10;
Test5.printx (x);
System.out.println ("main:x=" +x);
}
The results of the operation are as follows:
printx:x=11
main:x=10
Thus, when the base data type X is passed to the Printx method, only the value 10 is passed to the parameter x, so the parameter X plus 1 outputs 11, while the X in the main method is still 10.