|OCPJP 6|
matej spac wrote:Hi Ravi,
the rule is:
The overriding method must NOT throw checked exceptions that are new or broader than those declared by the overridden method.
Line 7 cause a compile error, because it declare broader exception:
SubException is subclass of Exception, so Exception is broader.
Line 10 cause a compile error based on rule I wrote above: Overriding method cannot throw new or broader exception.
Method doStuff() on line 10 declare that it throws FileNotFoundException, which is totally different and new kind of exception.
Line 8 is OK, because it is not overriding. Because of doStuff(int x) has a parameter, it is overloading instead of overriding.
|OCPJP 6|
Ravi Chandanani wrote:
is if class C extends class B,class B extends class A,class A extend Exception.
The class C is broader than class B and class B is broader than class A and class A is broader than class Exception.
If i am correct here,then class SubException would be broader class than class Exception.
|OCPJP 6|