Head First Java Chapter 9 constructor and garbage collector

Source: Internet
Author: User

A constructor is a special function. Its main function is to initialize the object when the object is created, that is, to assign an initial value to the V Object member variable, and always use it with the new operator in the statement that creates the object. Constructors are the same as class names, and you can overload multiple different constructors. In the Java language, constructors are the same as constructors in the C + + language, which is commonly referred to as construction methods in the Java language. The construction method is a special method, which has the following characteristics. (1) The method name of the construction method must be the same as the class name. (2) The constructor method does not have a return type and cannot be defined as void, and the method type is not declared before the method name. (3) The main function of the construction method is to accomplish the initialization of the object, which can pass the parameters that define the object to the domain of the object. (4) A class can define multiple construction methods, and if a constructor is not defined when the class is defined, the compiled system automatically inserts a default constructor with no parameters, which does not execute any code. (5) The construction method can be overloaded, with the number of parameters, type, order.

Head First Java Chapter 9 constructor and garbage collector

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.