Calls between JAVA constructor methods

Source: Internet
Author: User

This: Looks like the case for distinguishing between local variables and member variables
This is the object that represents this class, this represents the reference to the object to which the method belongs.
Calls between construction methods can only be done by the this statement
The This statement can only appear in the first row when the call is made between constructors, the constructor is executed first, and if there is initialization in the initialization, the more detailed initialization

classg{PrivateString name; Private intAge = 19;        G (String name) {System.out.println (name);        System.out.println (age); System.out.println ("The above output is a method of constructing a parameter"); } G (String name,intAge ) {         This(name);//call other constructors of the current objectSystem.out.println ("Here is a method of constructing two parameters"); }}/*this: It appears to be used to differentiate between local variables and member variables this: that is, representing this class of objects, this represents the reference to the object in which the method belongs, the call between the constructor method can only be made through the this statement to complete the call between the constructor method, the this statement can only appear in the first row, The construction method is executed first, and if there is initialization in the initialization, then the more detailed initialization is performed .*/ Public classindex{ Public Static voidMain (string[] args) {G G1=NewG ("Xiaoming", 19); }}

Calls between JAVA constructor methods

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.