Home  >  Article  >  Java  >  How to set parameters of java overloaded method

How to set parameters of java overloaded method

PHPz
PHPzforward
2023-04-28 11:13:15707browse

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete