Overloading of Java methods

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.