Java SE 16th Talk----Method overloading

Source: Internet
Author: User

1. Method overloading (Overload): Indicates that two or more methods have the same name but different method parameters

Different: 1) The number of parameters is different;

2) different parameter types; Note: The return value of the method has no effect on overloading

2. To construct a method overload, just look at the parameters. If you want to invoke another constructor method in one of the constructor methods, you can call the This () method with the parameter in parentheses to represent the parameters of the target constructor method. This () must be used as the first statement of the constructor method, in other words, this () cannot have any executable code before

 Public classConstructoroverload { Publicconstructoroverload () { This(3);//must be placed in this line System.out.println ("Test"); }         PublicConstructoroverload (inti) {System.out.println (++i); }      Public Static voidMain (string[] args) {constructoroverload CD=Newconstructoroverload (); }

The results of the operation are as follows:
4Test

Parse: New An object that invokes the constructor method, runs this (3) When the constructor method is called, executes the following constructor, outputs 4, and then outputs the test

Java SE 16th Talk----Method 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.