java--Construction Method

Source: Internet
Author: User

In a class, you can define a special method-the construction method.

Construction method: Used primarily to create objects, which can specify the state of an object at the same time.

The main differences between the construction method and the common method are:

1. Cannot have a return value.

2. The name of the construction method must be exactly the same as the class name that contains the constructor method of the class.

Attention:

A constructor with parameters is written, the value of the parameter must be specified when the object is created, and if the constructor method is not written, the compiler creates a parameterless construction method by default.

In a class, you can define multiple construction methods, which involve overloading the method.

Because the constructor name must be exactly the same as the class name, the compiler can only differentiate between different construction methods by the number, type, and order of the arguments.

The Java compiler uses a method signature (collectively known as the method name and parameter list) to distinguish between different methods, the method name and the parameter list, excluding the return value.

java--Construction Method

Related Article

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.