What is the difference between a construction method and a common method in Java?

Source: Internet
Author: User

The method of construction is different from the normal method.

There are two types of methods that can be defined in a class, the method of construction and the common method, but the two methods are obviously different when they are called.

1. The constructor method is called only once when instantiating a new object

2. The normal method is called multiple times by the object method after the instantiation of the object is generated.

If void is used on a construction method, its definition is exactly the same as the normal method, and the program compiles by defining the structure to parse it. Therefore, there can be no return value in the case.

  In addition, the most important difference between a constructor method and a normal method in a class is that the constructor is called directly when using the keyword new, which is the operation performed together with the object creation.

What is the difference between a construction method and a common method 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.