So you have a child and parent classes. The child
class extends from the Parent
class as follows.
[wp_ad_camp_5]
Normally, when overriding a method most of us just copy the same method signature from the parent class.
[wp_ad_camp_4]
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.
1 2 3 4 5 6 7 8 9 |
@Override public void printName(String name){ // You still need to handle the exception from super.printName(name) try { super.printName(name); } catch (Exception e) { e.printStackTrace(); } } |
This will not force your calling codes to declare or handle the exception.
[wp_ad_camp_3]