Home > Java > javaTutorial > body text

How to set parameters of java overloaded method

WBOY
Release: 2023-05-27 16:13:06
forward
1305 people have browsed it

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);
   }
}
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template