Java constructor details

Source: Internet
Author: User
Tags constructor

When an object is created, the corresponding constructor is called.

Constructor: used to initialize an object.

Constructor details:

If no constructor is defined in a class, the system adds an empty constructor to the class by default.

After you customize the constructor in the class, the default constructor will no longer exist.

Constructor and general functions are different in writing.

The operation is also different.

The constructor runs as soon as the object is created. Initialize the object.

The general method is executed only when an object is called, and the function of adding an object to an object is provided.

 

An object is created, and the constructor only runs once,

The general method can be called multiple times by this object.

When can I define constructors?

When analyzing a thing, the thing has some features and the latter behavior, so the content is defined in the constructor.

Construct a code block.

Purpose: initialize the object.

The object runs as soon as it is created and takes precedence over constructor execution.

Difference from constructor:

Construct a code block to initialize all objects in a unified manner,

The constructor initializes the corresponding object.

The constructed code block defines the initialization content that is common to different objects.

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.