Java Object-oriented constructors

Source: Internet
Author: User

When using new to create an object, it is called a function, the name of the function is called the constructor

Features of the constructor:

1. The name of the constructor must be exactly the same as the class name, including case.

2. The constructor does not write the return value, and does not write the return value, which means that even void is not written.

3. If the developer does not have any constructors, the Java virtual opportunity automatically creates a constructor with no parameters, and does nothing in this function.

4. Once a developer creates a constructor, the JVM will no longer create constructors with no parameters!.

5. Constructors can only be called with new, and cannot be invoked with objects.

6. In Java, a function with the same name can exist, as long as the function's parameter type is different, such a function is called the overload of the function.

I. An example of this pointer in a constructor and its memory model

Related examples

Memory model

Two. Common function problems in constructors

Related examples

Rn2 This method is not possible, because there is no constructor without parameters, the program is not found, so the compilation will be wrong.

Three. function overloading in constructors

Related examples

In Java, a function with the same name can exist, as long as the function's parameter type is different, this is called the function overload.

In the call process know which one to call is the line, clear parameters!

Java Learning Group 669823128

Java Object-oriented 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.