Using the class defined in the previous page slide, the following code outputs what the result is

Source: Internet
Author: User

1) How to construct a class

① "Construct Method", also known as "constructor", when an object is created, its construction method is automatically called. The constructor method is the same as the class name, with no return value.

② if the class does not have a constructor defined, theJava compiler automatically gives it a "default constructor" without parameters at compile time. If a class provides a custom construction method, the default construction method is no longer provided by the system.

③ A class can have more than one constructor, and multiple constructors are distinguished by parameters.

(2) class initialization block

You can use "{" and "}" in your class toenclose the statement directly as a member of the class. This "No Name" member of the class is used to initialize the fields of the class.

(3) The default value specified when executing the class member definition or the initialization block of the class, exactly which one you want to see is "in front".

Using the class defined in the previous page slide, the following code outputs what the result is

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.