Java Learning--overloading of methods

Source: Internet
Author: User

* Overloading of methods (overload)
* Requirements: 1. In the same class 2. The method name must be the same 3. The parameter list of the method is different (the number of ① parameters differs ② parameter type)
* Supplement: The overloads of the method have no relation to the return value type of the method!
 Public classTestoverload {}classoverload{//defines the and of two variables of type int     Public intGetsum (intIintj) {        returni +J; }    //defines the and of three variables of type int     Public intGetsum (intIintJintk) {        returni + j +K; }    //cannot be overloaded with several other methods//public int getSum1 (int i,int j,int k) {//return i + j + K;//    }//Public void getsum (int i,int j,int k) {//System.out.println (i + j + k);//    }    //defines the and of two double type data     Public DoubleGetsum (DoubleD1,DoubleD2) {        returnD1 +D2; }        //defines the and of three array of type double     Public voidGetsum (DoubleD1,DoubleD2,DoubleD3) {System.out.println (D1+ D2 +D3); }    //the following two methods form an overload.      Public voidMETHOD1 (inti,string str) {            }     Public voidMethod1 (String str1,intj) {            }} 

Java Learning--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.