Home >Java >javaTutorial >How to set parameters of java overloaded method
1. In order to overload a method, the parameter list of the method must be different in two aspects.
2. Three aspects of the parameters of the overloaded method, the number of parameters, the data type of the parameters and the order of the data types of the parameters.
Example
class DisplayOverloading { public void disp(char c) { System.out.println(c); } public void disp(char c, int num) { System.out.println(c + " "+num); } } class Sample { public static void main(String args[]) { DisplayOverloading obj = new DisplayOverloading(); obj.disp('a'); obj.disp('a',10); } }
In the above example, - the method disp() is overloaded based on the parameters - we have two methods with the name disp but they There are different parameters. Both have different parameters.
The above is the detailed content of How to set parameters of java overloaded method. For more information, please follow other related articles on the PHP Chinese website!