1.

What Are The Rules Of Exception Handling With Respect To Method Overriding?

Answer»

There are certain restrictions while overriding a method in case of exception handling in Java. BROADLY there are TWO rules -

  • If superclass method has not declared any exception using throws CLAUSE then subclass overridden method can't declare any CHECKED exception though it can declare unchecked exception.
  • If superclass method has declared an exception using throws clause then subclass overridden method can do one of the three things.
  • sub-CLASS can declare the same exception as declared in the super-class method.
  • subclass can declare the subtype exception of the exception declared in the superclass method. But subclass method can not declare any exception that is up in the hierarchy than the exception declared in the super class method.
  • subclass method can choose not to declare any exception at all.

There are certain restrictions while overriding a method in case of exception handling in Java. Broadly there are two rules -



Discussion

No Comment Found