Summary of this in java

Source: Internet
Author: User

This is used in the constructor. When the constructor of different parameter lists is used, if the constructor has the same function as another constructor, the constructor can call the function of the constructor.

Format:

This (value );

 

 

Class Test

{

Test () {...} // constructor with null Parameters

Test (Datatype var) // constructor with a parameter

{

This ()

....

}

 

Test (Datatype var1, Datatype var2) // constructor with two parameters

{

This (var1 );

........

}

Test (Datatype var2, Datatype var2, Datatype var3)

{

This (var1, var2 );

.......

}

}

========================================================== ==========================================================

This is used in constructors.

Format:

This. function (value );

 

Class Test

{

Public void function () // a function without Parameters

{

Function 1;

}

 

Public void function (Datatype var) // function with one parameter

{

Function 1;

Function 2;

}

 

Public void function (Datatype var1, Datatype var2)

{

Function 1;

Function 2;

Function 3;

......

 

// Equivalent

// This. function (var1); // => function 1; function 2;

// Function 3;

}

}

 

 

========================================================== ==========================================================

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.