Java-Constructor (Blind analysis)

Source: Internet
Author: User

Construction Method:

  A constructor method is a special method that cannot create a new object without constructing a method. In fact, creating an object not only calls the constructor of the actual type of the current object, but also calls the constructor of the parent class until the object class. The construction method does not have to show the call, and when the new keyword is used, the corresponding construction method is automatically called.

Rules for constructing methods;

1, the construction method can use any access modifier. including private

2. The construction method must have the same name as the class name (this is the specification, for the specification, only the first letter of the construction function is capitalized)

3, the construction method can not have a return value (the return value is not a constructor)

4. If you do not create your own constructor method in the class, the compiler automatically generates a default constructor with no parameters (as the Java Anti-compilation tool can see)

5. If you only create a constructor with parameters, the compiler does not automatically generate an argument-free construction method

6. In each constructor, if you use the overloaded construction method this () method, or the constructor method of the parent class super () method, then this and super must be placed in the first row, and two methods can only be selected, and there is no sequential problem between them.

7, in addition to the compiler auto-generated construction method, and does not explicitly call the super () method, the compiler will automatically insert a super () no parameter call

8, the abstract class has the construction method

The analysis is done.

Java-Constructor (Blind analysis)

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.