Day1-java-construction method and its destructor method

Source: Internet
Author: User

The purpose of the construction Method (constructor) is to initialize objects when they are created, and a class can have multiple constructors that differentiate them from the overloads of the constructor (overload) depending on the number of arguments or the difference in the parameter type.

Features: 1. Each class has a constructor method, and an empty construction method is automatically generated without it.

2. The construction method is consistent with the class name.

3. The function of the constructor is primarily used to define the state of the initialization when the object of the class is created. It has no return value and cannot be decorated with void.

4. The constructor is not explicitly called and is called automatically when the object is created. Sometimes the parent class has a constructor that takes a parameter, and the constructor for calling the parent class must be displayed in the subclass, because the constructor of the subclass cannot find the constructor of the parent class when it is instantiated (the subclass does not have to show the call when the parent class has its own write-without-argument constructor).

There is no destructor method (destructor) in Java, but there is a similar finalize () method in object, and the Finalize method of the class is automatically called when the system is reclaimed. In a generic subclass, the Finalize method of the parent class is called to ensure that the parent collection works properly.

Day1-java-construction method and its destructor 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.