How to construct classes in Java

Source: Internet
Author: User

Primary role: Initialize member variables (attributes)

For example:

Class Person

{

int age;

String name;

/*

Public person ()

{

}

*/Default Construction method

}

Class Person

{

int age;

String name;

public person (int age, String name)

{

Age = age;

name = name;

}

}

A method that is constructed by itself overrides the default constructed

The construction method of the class is summarized as follows:

1. The construction method name and the class name are the same;

2. The construction method has no return value;

3. The main role is to complete the initialization of new objects;

4. When creating a new object, the system automatically calls the construction method of the class;

5. Each class has a default construction method;

6. A class can have more than one construction method.

How to construct classes 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.