Parsing and usage of this in Java

Source: Internet
Author: User

Java memory can be divided into the stack area, the heap area and the method area.

Stack area: A space that is automatically allocated for continuous allocation, which is used to store local variables defined in the program.

Heap area: A discontinuous memory space used to hold object instance data allocated by the New keyword.

Method Area: The method area is used to store code information for a class, static variables, and constant pools-object type data, and so on.

For example, the instance method is stored in the object instance data, and when we define an object and invoke an instance method of it using that object, the pointer of the method needs to go to the code of the method called in the object type data,

However, the instance method involves the reading and writing of other properties in the calling object, so the virtual opportunity implicitly passes the address of the keynote object to the modulated method when the part code is called, which is implicitly passed to the address

is the this pointer.

Thus, if the this pointer is used in an instance method to invoke the object's properties (such as a), it is clear to which object THIS.A is a, because there may be more than one object of that type.

The this pointer can also do this (parameter) in the first statement of the constructor method; Call, which implements the constructor method call construction method. But this usage requires that the modulated method be constructed in the first

Statement.

Parsing and usage of this in Java

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.