What is a Java method overload
definition of method overloads
- 1
For the same class, if there are two or more methods with the same name in the class, but the method has at least a different number of parameters, type, and order, this time the Bureau constitutes a method overload.
END
Method overloading Example
- 1
public class test{
public void A () {
};
public void A (int i) {
};
}
Description: There are two methods in the test class with the same name, both a. When you call method A, if you do not pass the parameter, the first method A is called automatically, and if a parameter of type int is passed in, the system calls the second method A.
- 2
public class test{
public void A (int i) {
};
public void A (String j) {
};
}
Description: There are two method A with the same name in the test class. When the method is called, if a parameter of type int is passed, the first a method is called automatically, and the second method A is called automatically if a parameter of type string is passed in.
- 3
public class test{
public void A (int i,string j) {
}
public Class A (String j,int i) {
}
}
Description: There are two methods with the same name in the test class. When the method is called, the first method A is automatically called if the first parameter type passed in is int and the second argument is a string. If the first parameter passed in is of type string and the second argument is int, the second method A is called automatically.
END
The role of method overloading
- 1
Method overloading is the implementation of similar operations on data of different data types.
Java Method--Overloading 2