Java Method--Overloading 2

Source: Internet
Author: User

What is a Java method overload definition of method overloads
    1. 1

      For the same class, if there are two or more methods with the same name in the class, but the method has at least a different number of parameters, type, and order, this time the Bureau constitutes a method overload.

      END
Method overloading Example
    1. 1

      public class test{

      public void A () {

      };

      public void A (int i) {

      };

      }

      Description: There are two methods in the test class with the same name, both a. When you call method A, if you do not pass the parameter, the first method A is called automatically, and if a parameter of type int is passed in, the system calls the second method A.

    2. 2

      public class test{

      public void A (int i) {

      };

      public void A (String j) {

      };

      }

      Description: There are two method A with the same name in the test class. When the method is called, if a parameter of type int is passed, the first a method is called automatically, and the second method A is called automatically if a parameter of type string is passed in.

    3. 3

      public class test{

      public void A (int i,string j) {

      }

      public Class A (String j,int i) {

      }

      }

      Description: There are two methods with the same name in the test class. When the method is called, the first method A is automatically called if the first parameter type passed in is int and the second argument is a string. If the first parameter passed in is of type string and the second argument is int, the second method A is called automatically.

      END
The role of method overloading
    1. 1

      Method overloading is the implementation of similar operations on data of different data types.

Java Method--Overloading 2

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.