Let's take a look at the differences and relationships between variables and objects in Java.
- If the parameter type is basic, it is passed by value.
- If the passed variable type is of the class type, it is passed by reference.
- Function return values are classified into basic types and class types like parameter passing methods.
- The details are as follows:
F (person local)
Main ()
{
Person man;
F (man );}
In the above Code, there are two types of local operations
- If a value is assigned to the local value in the f function, the local value points to the memory of another object as a local variable. man in main still points to the memory corresponding to the original object. in this case, the local does not change man in main. we can think they have separated.
- If the value of a local field is modified in F, or a local built-in method is called, this method can change the value of a local field. in this case, because both local and man point to the same memory object, changes to some local fields will be reflected in man in main. at this time, we still think that local and man are still eating in the same pot.
2. Local variables in the function: the local variables in the function are destroyed when the function returns