The difference between Overload and Override. Can overload methods be differentiated based on the return type ?, Overloadoverride

Source: Internet
Author: User

The difference between Overload and Override. Can overload methods be differentiated based on the return type ?, Overloadoverride

Both overloading and rewriting are the embodiment of polymorphism. The difference is that overloading is the polymorphism at compilation and rewriting is the polymorphism at runtime;

Overload: only occurs in one class. It is distinguished by the same name of the method and different parameter types or number of parameters.

Rewriting: between the parent class and the subclass, rewriting requires that the override method of the subclass must have the same return type as the override method of the parent class, which is better accessed than the method of the parent class, it cannot declare more exceptions than the method whose parent class is overwritten, but the overload does not have special requirements for the return type.

Can overload methods be differentiated based on the return type?

No. If the return type is used to distinguish public void test1 () {}and publiv String test1 () {return "" ;}( compilation failed) in the same class) if the compilation is successful, the class is used when the method is proposed. test1 cannot identify which method is called

 

This article is taken from the JAVA interview book

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.