Java-cannot reduce the visibility of the inherited method from the parent class

Source: Internet
Author: User
Tags visibility
java-cannot Reduce the visibility of the inherited method from parent class 2014-08-20 22:12 1561 people read comments (0) Collection report

Copyright NOTICE: This article is the original article of the blogger, without the permission of the blogger may not be reproduced.

2014-07-17 10:38 by Schrodingercat


In Java, when Class A inherits Class B, there is a provision in class B that overrides (or is called/override) Class A, and that is: the scope of the permission modifiers for the subclass of the method should be greater than or equal to the parent class.

Class a{

protected method () {}

}

Class B extends a{

Private method () {}

Private is wrong, there will be an error message: Cannot reduce the visibility of the inherited method from B

Either the Protected,public or the default (not added) are compiled correctly.

}

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.