Java Review Note--java the This keyword

Source: Internet
Author: User

The This keyword in java, this can call the Class's member variables and member methods, and this can also call a constructor method in the Class. in this way, it is worth noting that

You can only use the This keyword in the first sentence of the parameterless constructor method to invoke a parameter construction method.

 public class anythting{    public  anythting () {        This ("the this call has a parameter constructor method");        SYSTEM.OUT.PRINTLN ("non-parametric construction method")    ;    }  public anythting (String name) {        System.out.println ("constructive method");}    }

Create a class file in your project that defines the SetName () method and assigns the parameter value of the method to a member variable in the class.

Private        void setName (String name) { // defines a setName () method for This. name = name; // assigning a parameter value to a member variable in a class }  

The This keyword is implicitly used to refer to the member variables and methods of an object, as in the preceding code, this.name specifies the name member variable in the book class.

The second name in the THIS.NAME = Name statement specifies the formal parameter name

In fact, This reference is a reference to an Object.

Java Review Note--java the This keyword

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.