Java_se basic--17. Overloading of methods

Source: Internet
Author: User

method overloads:Method overloading is the method name repetition and loading parameters are different. Specific Specifications:
I. The method name must be the same. Two. The parameter table of the method must be different, including the type or number of parameters, to distinguish between different method bodies. 1. If the number of parameters is different, regardless of its parameter type! 2. If the number of arguments is the same, then the order of the parameters must be different. Three. The method's return type, modifiers can be the same, or different.
Examples of overloading include the ability to add two integers, add three integers, and add two decimals in code.
public class Example17 {public static void main (string[] args) {///The following is a call to the summation method int sum1 = Add (1, 2); int sum2 = Add (1, 2, 3 );d ouble sum3 = Add (1.2, 2.3);//The following code is the result of printing the sum System.out.println ("sum1=" + sum1); System.out.println ("sum2=" + sum2); System.out.println ("sum3=" + sum3);} The following method implements the addition of two integers public static int add (int x, int y) {return x + y;} The following method implements the addition of three integers public static int add (int x, int y, int z) {return x + y + z;} The following method implements two decimals added public static double add (double x, double y) {return x + y;}}

The results are as follows:


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java_se basic--17. Overloading of methods

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.