On overloading of Java methods
Method overloading means that multiple methods with the same name but different parameters can be defined in a class. When calling, the corresponding method will be selected according to the unused parameter table
such as
Output is:
Construction methods can also be overloaded
Let's take another example
The above is an overload, and the overload must meet the following conditions: 1 Must be the same class 2 The method name (also called function) is the same. 3. The parameter types are different or the number of parameters is different
At the same time, I'll also tell LZ about the role of overloading. Let's use the above example
As mentioned above, which method to call is determined by the program according to the parameters you enter
Let's also talk about the function of overloading. For example, if you play a game, there may be more than one person in the game, and the number of people is uncertain. Then you can use overloading
For example, you can define three parameters if at most three people finish
If there are two people, you can call the method with two parameters. If there are three people, you can call the method with three parameters. How to call the method has been described above