/***** @ 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