JAVA learning-method overloading, java-overloading

Source: Internet
Author: User

JAVA learning-method overloading, java-overloading

 

* Method 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 is different ② the parameter type is different)
* Supplement: Method Overloading is irrelevant to the return value type of the method!
Public class TestOverload {} class OverLoad {// defines two int variables and public int getSum (int I, int j) {return I + j ;} // defines the sum of the three int variables and the public int getSum (int I, int j, int k) {return I + j + k ;} // cannot be overloaded with 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 two double-type data and public double getSum (double d1, double d2 ){ Return d1 + d2;} // defines the three double arrays and public void getSum (double d1, double d2, double d3) {System. out. println (d1 + d2 + d3);} // The following two methods constitute overload. Public void method1 (int I, String str) {} public void method1 (String str1, int j ){}}

 

Related Article

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.