References and objects in Java, parameter passing, and variable scope

Source: Internet
Author: User
Let's take a look at the differences and relationships between variables and objects in Java.
  1. If the parameter type is basic, it is passed by value.
  2. If the passed variable type is of the class type, it is passed by reference.
  3. Function return values are classified into basic types and class types like parameter passing methods.
  4. The details are as follows:
F (person local)
Main ()
{
Person man;
F (man );}
In the above Code, there are two types of local operations
  1. 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.
  2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.