java--Construction Method

Source: Internet
Author: User

The constructor method is a special method with the same method name as the class name and no return type, which is used to produce the object (which helps to produce the object).

The function of the construction method:

1, allocating space for objects

2, initialize member variables

3, returns a reference to the object

If a class does not have a construction method defined, the virtual opportunity is automatically assigned an parameterless construction method. However, if a class defines a construction method, the default parameterless construction method disappears.

Super () calls the constructor of the parent class, produces the parent class object, inherits from the parent class, and if the constructor of the parent class is not called by Super () in the subclass constructor method, the parent class object is generated. Virtual opportunity automatically adds super ().

and super () must be the first sentence of the subclass construction method. If no parameter construction method is provided in the parent class. Then the subclass must be called through Super (argument). Otherwise, the subclass cannot make a call to the parent class without a parameter construction method by the bucket super (). thereby compiling the error.

java--Construction Method

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.