Learn to program the Java Tutorial common method overload published, Welcome to visit through the xuebiancheng8.com
First look at what is a common method overload, first look at an example
public class person{
String username;
int age;
public void Hello () {
System.out.println ("Hello");
}
public void Hello (String username) {
System.out.println ("Hello" +username);
}
public void Hello (int.) {
System.out.println ("Hello" +age);
}
}
Then there is the following code:
Person P =new person ();
P.hello ();
P.hello ("Zhang San");
P.hello (20);
Output Result: Hello
Hello, Zhang San.
Hello, 20
The above example is the common method overload, their common feature is the same method name, the parameter list is different. The method that is called is determined by the parameters of the call.
Common method overloads require the following characteristics:
The method name is the same, the argument list must be different, and the access control and return values are not related.
There are a few things that are different in the parameter list
1. Different number of parameters
2. Parameter list order is different
3. Different types of parameters
Any of these features can be overloaded.
For more Java method overloaded content, please visit xuebiancheng8.com
The specific URL is
Http://xuebiancheng8.com/play/goodgoodstudy_96_daydayup.html
Common ways to learn Java tutorials overload