What is method overloading in java
This article introduces the relevant knowledge of "what is method overloading in java". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
What is the overloading of methods?
Method overloading is a means of dealing with different data types in a unified way.
How to constitute the overload of the method?
The method name is the same, but the parameter is different. And the difference between the parameters is expressed in:
1)。 The number of formal parameters is different.
2)。 The types of parameters are different.
3)。 The overloading of different methods in the order of formal parameters is mainly the problem of ending the same method, but with different parameters.
For example, compare the size of two integers and compare the size of two floating-point numbers
Public class Testmax {/ * * main method * / public static void main (String [] args) {int I = 5; int j = 2; int k = max (I, j); System.out.println (I + "and" + j + "comparison, the maximum value is:" + k "); float n = 2.3F; float mast 24.5F; float c=max (NMagnem); System.out.println (n +" he "+ m +" zuidashi "+ c) } / * * returns the larger value of two integer variables * / public static int max (int num1, int num2) {int result; if (num1 > num2) result=num1; else result=num2; return result;} public static float max (float num1,float num2) {float result; if (num1 > num2) result=num1; else result=num2; return result;}}
This is the end of the content of "what is method overloading in java". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!