4 _ Overloading)

Source: Internet
Author: User

This is also called method overload.
1. Two or more functions are in the same class;
2. The function names are the same;
3.The parameter list is different (including the type and number of parameters and the order of parameter types );

 Public   Class  Ol {  Void  Funol () {system. Out. println ( "Funol functions without Parameters" );}  Void Funol ( Int  I) {system. Out. println ( "Funol function with one parameter" );}  Void Funol ( Int I, Float  J) {system. Out. println ( "Funol functions with two parameters" );}  Void Funol ( Float J, Int  I) {system. Out. println ( "I am also a funol function with two parameters" );}} 


Understanding: although the function name is the same, the function functions are different. Just like this function, you can wash your face, take a bath, and wash dishes;
ProgramTo identify which function to call, it is determined by the parameter list.
For exampleAn error occurs.Because the parameter list is identical, this is an error that is repeatedly defined by the same function and the compiler does not pass

VoidFunol (IntI,FloatJ) {system. Out. println ("Funol functions with two parameters");}VoidFunol (IntI,FloatK) {system. Out. println ("There are also two parameters");}


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.