Constructors in Java

Source: Internet
Author: User

The main construction method is to create an instantiated object of the class, but the initialization of the instantiated object is done. Declaration format:

Constructor method's modifier list class name (method parameter list)

Construction methods can be overloaded as well as normal methods.

Characteristics of the construction method:

  1. The constructor method name must be exactly the same as the class name.

  2. The constructor method does not have any return value type, neither the return value nor the shut-off void can be joined, but it is not a construction method, it becomes the common method.

  3. any construction method, if there is no definition displayed, the system defines a default constructor for the class that does not contain any arguments . If the constructed method is defined, the default constructor with no parameters is not created by the system.

Recommendation: When writing a construction method, be sure to add a parameterless construction method.

This article is from the "Gaogaozi" blog, make sure to keep this source http://hangtiangazi.blog.51cto.com/8584103/1661087

Constructors in Java

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.