0

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.

11-11-2016-5-00-37-pm

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

11-11-2016-5-01-34-pm

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.

Karl San Gabriel

Karl San Gabriel

Java and Enterprise Technologies Expert