Older Dick Silk Self-study note--java 0 basics to rookie--012

Source: Internet
Author: User

Methods, overloading

1. Method: A block of code to complete a specific function

Format: Modifier Returns the value of the method name (argument type parameter name 1, ..., argument type parameter name N) {function body; return value;}.

Note: the "void" method does not require a return value and the method cannot be nested.

1 classfin{2 3     //Main Method4      Public Static voidMain (string[] args) {5         intN=test (3,2);//Call the test method6SYSTEM.OUT.PRINTLN (n);//n=17     }8 9     //test MethodTen      Public Static intTestintAintb) { One          returnA-b; A     } -}

2. Overloading: A method in the same class that allows different parameters of the same name (parameter types or different number of parameters)

Note: Regardless of the return value of the method, just look at the method name and parameter (parameter type, number of arguments) and distinguish the method with the same name by parameter.

1 classfin{2      Public Static voidMain (string[] args) {3         intN=test (3,2,1);4SYSTEM.OUT.PRINTLN (n);//n=65     }6 7      Public Static intTestintAintb) {8         returnA-b;9     }Ten  One      Public Static intTestintAintBintc) { A         returna+b+C; -     } -}

Older Dick Silk Self-study note--java 0 basics to rookie--012

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.