Java Constructors (constructors)

Source: Internet
Author: User
Tags modifier

A constructor is a block of code that initializes an object immediately after the object is created. The structure of the constructor looks similar to a method.

declaring constructors

The general syntax for a constructor declaration is:

123 <Modifiers> <Constructor Name>(<parameters list>) throws<Exceptions list> {}

The declaration of the constructor begins with a modifier.
The constructor can have its access modifier: public , private , protected or package-level (no modifier).

The constructor name is the same as the name of the class. The constructor name is followed by a pair of parentheses, which may include parameters. Optionally, the right parenthesis can be followed by a keyword followed by throws a comma-delimited list of exceptions.

The following code shows an example of a constructor that declares a class Test . The name of the class and the name of the constructor must match.

Click on the link to view the details

Java Constructors (constructors)

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.