Package com.test;
Method overloading (overload) Definition:
1. Method names are the same
2. The method has at least one different parameter type, number, and order
3. The return type of the method can be different
4. The modifier of the method can be different
The concept of Overload: It is the multiple implementations of the same function of a class, depending on the parameters given by the caller.
public class Test2 {
/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
ABC ABC1 = new ABC ();
Different invocation methods for output objects
System.out.println (Abc1.getmax (1, 2));
System.out.println (Abc1.getmax (1, 0, 2));
}
}
Class ABC
{
Define a temporary variable
private float temp;
Compare to the previous method of each method
public int Getmax (int i, int j)
{
if (I>J)
{
return i;
}
Else
{
Return J;
}
}
Different parameter types
public float Getmax (float i, float j)
{
if (I>J)
{
return i;
}
Else
{
Return J;
}
}
Different number of parameters
public float Getmax (float i, float j, float K)
{
if (I>J)
{
temp = i;
}
Else
{
temp = j;
}
if (temp < k)
{
temp = k;
}
return this.temp;
}
}
Overloading of Java methods