2018.5.7 class notes (about method parameters)

Elements of method concern:
to whom the
method The parameters of the method

method return value

The transmission of parameters is "pass by value". When the method is called, a copy of the parameter will be created, and the original value will not be changed.

Primitive data types, also known as "value types".

There are two ways to pass parameters to a method (or function).

A pass-by-value means that the method accepts the value provided by the caller;

When the received formal parameter is a basic data type, the value of the original variable will not change.

The stack area stores the value of the original variable. After the method is received, the stack area stores a copy of the original variable. The value of the copy is in the constant pool, and the two do not affect each other.


2. Call by reference means that the method accepts the variable address provided by the caller;

When the received formal parameter is a reference data type (that is, a class type), if the related properties of the object are modified in the incoming method, the related properties of the original object will also be changed.

The heap area stores the reference address. After receiving through the method, the modification of the relevant properties of the object, but no matter how many variables of the same type are defined externally, the original object itself is modified, and it is a shared reference address.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325750242&siteId=291194637