Java review 12

Source: Internet
Author: User

Overr ide rewriting and overload Overloading

 

When an inherited relationship occurs, you can use the super keyword to reference the parent method. If you want to use a new method, you can rewrite it to meet the new function requirements.

The reload is summarized as follows:

 

You can only define different parameter lists when using overload.

 

The returned type, access permission, and thrown exception of the overloaded method cannot be used.

Method overload.

 

The rewrites are summarized as follows:

 

The override method exists in the parent class and also in the subclass.

 

The method of rewriting adopts the form of polymorphism at runtime.

 

The method to be rewritten cannot have higher access restrictions than the method to be rewritten.

 

The method to be rewritten cannot have more exceptions than the method to be overwritten.

The reload is summarized as follows: • different parameter lists can be defined only when reload is used. • Methods cannot be overloaded by the return type, access permission, and thrown exceptions of the overloaded method. • Rewrite is summarized as follows: • The override method exists in the parent class and also in the subclass. • The method of rewriting adopts the form of polymorphism at runtime. • The method to be rewritten cannot have higher access restrictions than the method to be rewritten. • The method to be rewritten cannot have more exceptions than the method to be rewritten.

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.