Method overloading and overriding differences, method overloading overrides the _php tutorial

Source: Internet
Author: User

Method overloading and overriding differences, method overloading overrides the difference


Answer one: Fundamental differences:
Rewrite (refactoring) is very intuitive ah, the child class overrides the parent class with the same name as the return value of the method, called by the subclass is only the overridden method
Overloaded with the same name. Answer two: 1. Overloading:
Method name is the same, parameter list is different
2. Rewrite:
Also called overwrite, which defines a method in a subclass that has the same name as the argument list of a method in the parent class. Because subclasses inherit the methods of the parent class, overriding is redefining the method inherited from the parent class and re-filling the code in the method.
Answer three:
Overriding is a method of a subclass that overrides a method of the parent class, requiring the method name and parameters to be the same

Overloading is two or more than two methods in the same class, with the same method name, but the parameters are not the same, the method body is not the same, the most common example of overloading is the constructor of the class, you can refer to the API Help document to see the construction method of the class



Answer four:
1. Overrides must be inherited, not overloaded.
2. The overridden method name, the same number of parameters, the parameter type is compatible, the overloaded method name is the same, the parameter list is different.
3. The overridden method modifier is greater than or equal to the parent class's method, overloaded and modifier independent.
4. Overrides can not throw generic exceptions that are not thrown by the parent class, and can throw runtime exceptions

http://www.bkjia.com/PHPjc/1122389.html www.bkjia.com true http://www.bkjia.com/PHPjc/1122389.html techarticle Method overloading and overriding differences, method overloading override difference answer one: The fundamental difference: rewrite (refactoring) is very intuitive ah, the child class overrides the parent class with the same parameter as the return value of the method, with the child ...

  • 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.