Comparing overloads and Overrides for Java methods

Source: Internet
Author: User



Overloading (overload) Overwrite (override)
Concept Multiple methods of the same name that exist in the same class, with the same return value type and a different argument list A derived class redefined a method with the same name as a base class method, with the same return value type and argument list, except that the behavior is different
where it appears
In the same class In different classes that have an inheritance relationship
return value type
Same Same
Parameter list Different number of parameters or different parameter types Same
Characteristics Regardless of the return value type, focus only on the parameter list

(1) A derived class method can assign the same or greater access rights as a base class method

(2) A derived class cannot overwrite a base class method that is marked final

(3) A derived class method can throw an exception, subclass exception, run-time exception, or error that is the same as a base class method, but cannot throw a new exception or superclass exception

Application Scenarios Perform the same task and just enter a different scene, using the same name method for easy reading Scenarios in which inheritance behavior needs to be redefined are often the primary purpose of using inheritance relationships


This article is from the "Youth is the experiment Lesson of Life" blog, please make sure to keep this source http://liusibo.blog.51cto.com/1382721/1921233

Comparing overloads and Overrides for Java methods

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.