One of the most important parts of a method is the parameters of the method. Parameters are local variables. When the object calls the method, the parameters are allocated memory space and the caller is required to pass values to the parameters. That is, when the method is called, the parameter variables must have specific values. value.
In Java, the value of the parameter variable in the method is a copy of the value specified by the caller. If the method changes the value of the parameter, it will not affect the value of the variable "passing value" to the parameter.
Passing values of basic data type parameters:
For a parameter of a primitive data type, the value passed to the parameter cannot be of a higher level than the parameter's level.
For example: you cannot pass a float value to an int parameter, but you can pass a float value to a double parameter.
Pass-by-value for reference type parameters:
Java's reference data includes arrays, objects, and interfaces. When the parameter is a reference type, "pass by value" passes the "reference" stored in the variable, not the entity referenced by the variable.
Notice:
For two reference variables of the same type, if they have the same reference, they will have the same entity. Therefore, if the entity referenced by the parameter variable is changed, it will cause the same change in the entity of the original variable; however, changing the parameter The "reference" stored in will not affect the "reference" stored in the variable to which the value is passed.