Software Development

Java – Override method to not throw Exception

So you have a child and parent classes. The child class extends from the Parent class as follows.



Normally, when overriding a method most of us just copy the same method signature from the parent class.



Here, the overriden method printName throws an Exception as its parent version of printName. This will require any codes calling your overriden method to handle the Exception.

We could change the overriden method’s signature to this.

This will not force your calling codes to declare or handle the exception.


You Might Also Like