Java basic interview Summary 1

Source: Internet
Author: User
/***** @ Author fanqinglin * 1. when a subclass overwrites the method of the parent class, it can not throw the exception of the parent class, it can also throw an exception that is the same or smaller than the exception range of the parent class * 2. when a subclass overwrites a method of the parent class, the method names, number of method parameters, and type of the parent class and subclass must be consistent. * 3. when processing modifiers, if the parent class is private, the subclass overwrites the error because it cannot be inherited or is called unavailable * 4. if the parent class is protected, the subclass can be protected or public, that is, the subclass has a larger range than the parent class * 5. follow the inheritance principle: inheritance must ensure that the nature of the super class is still in the subclass is a relation */Class A {protected void Foo () throws exception {} Class B extends a {@ override public void Foo () throws ioexception, exception {} // allowed/* @ override public void Foo () throws {} // allowed * // * @ override public void Foo () throws sqlexception {} // not allowed */}

1) When overwriting a method, the method visibility of the subclass cannot be lower than that of the superclass. Reference: http://topic.csdn.net/u/20111129/11/efebbcb8-6e5d-45c4-a768-dea2b8e37abd.html
2) When overwriting a method, the subclass method should not throw a new or broader checked exception. Reference: http://stackoverflow.com/questions/5875414/method-overriding-and-exceptions

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.