Second, Java object-oriented (7) _ Packaging Ideas--this Keywords

Source: Internet
Author: User

2018-04-30

This keyword

What is this:

 Represents the current object itself, or an instance of the current class, through which all methods and properties of this object can be called.

This is mainly present in two places:

1) Constructor: This represents the invocation of the currently created object

2) member method: Object A calls the method where this is located, at which point this represents the object a

When an object is created, the JVM automatically assigns a reference to the current object's this

Memory Analysis:

  

Use of this:

1) Use this to distinguish between variables of the same name

When a member variable has the same name as a variable in a local variable (parameter), you want to call the member variable inside the method

2) Initialize the object as a method name (the method that the constructor reloads)

  This is equivalent to invoking the other constructor method of this class, which must be the first sentence of the constructor method.

3) Pass as parameter

You need to call a method in some completely detached class and pass a reference to the current object as a parameter.

Reference:

Http://www.weixueyuan.net/view/5988.html

Second, Java object-oriented (7) _ Packaging Ideas--this Keywords

Related Article

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.