Java Constructors and function overloading

Source: Internet
Author: User

Constructor: The ⑴ method name is the same as the class name, and there is no return type (including void);

⑵ no return value;

⑶ If there is no input constructor, the JVM will automatically help us create a constructor without parameters, without any function body;

If we created the other constructors manually, we would not have created this constructor without parameters;

⑷ in general, if you want to implement your own construction method, it is best to overload a constructor without parameters.

  

Function overloading: Refers to multiple functions can use the same function name, as long as their parameter list is different, the meaning of similar functions, named the same name.

Overload Summary: ⑴ function overloading means that multiple functions use the same name;

The condition of ⑵ overloading is that the number and type of parameters are different;

⑶ overload effect: Reduce the difficulty of the call;

⑷ when calling overloaded functions, the computer layer matches itself according to the arguments.

Examples:

Public Noddle () {
This.bowltype = "Large bowl";
}

Public Noddle (String b) {
Bowltype = b;
}
Public Noddle (String bowltype, String type, Boolean moremeat) {
This.bowltype = Bowltype;
This.type = type;
This.moremeat = Moremeat;
}

Java Constructors and function overloading

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.