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